Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Why do getWidth() and related functions always return 0?
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Keith Wiley  
View profile  
 More options Dec 9 2008, 12:24 pm
From: Keith Wiley <kbwi...@gmail.com>
Date: Tue, 9 Dec 2008 09:24:43 -0800 (PST)
Local: Tues, Dec 9 2008 12:24 pm
Subject: Why do getWidth() and related functions always return 0?
I'm perplexed why the dimension accessors on Views generally return
0.  I have specified fill_parent as their layout_width and
layout_height, yet calls to getWidth(), getRight(), etc. all return 0.

Does this make any sense?  How do I find out how big a view is?

Thanks.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Dianne Hackborn  
View profile  
 More options Dec 9 2008, 12:25 pm
From: "Dianne Hackborn" <hack...@android.com>
Date: Tue, 9 Dec 2008 09:25:35 -0800
Local: Tues, Dec 9 2008 12:25 pm
Subject: Re: [android-developers] Why do getWidth() and related functions always return 0?

Read the View docs on layout.

On Tue, Dec 9, 2008 at 9:24 AM, Keith Wiley <kbwi...@gmail.com> wrote:

> I'm perplexed why the dimension accessors on Views generally return
> 0.  I have specified fill_parent as their layout_width and
> layout_height, yet calls to getWidth(), getRight(), etc. all return 0.

> Does this make any sense?  How do I find out how big a view is?

> Thanks.

--
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support.  All such questions should be posted on public
forums, where I and others can see and answer them.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Wiley  
View profile  
 More options Dec 9 2008, 1:50 pm
From: Keith Wiley <kbwi...@gmail.com>
Date: Tue, 9 Dec 2008 10:50:14 -0800 (PST)
Local: Tues, Dec 9 2008 1:50 pm
Subject: Re: Why do getWidth() and related functions always return 0?
I'm sorry, I really don't know what you're trying to point me to.  I
have thoroughly read the docs for the class android.view.View.  Is
that what you're referring to when you say "View docs on layout" or do
you mean a different document?  I am afraid that while that
documentation is clearly thorough, it is not necessarily unambiguous,
as I still don't understand how to ask a view what its width is.

Sorry for the trouble.

Am I supposed to be reading some other documentation?

Thanks.

On Dec 9, 9:25 am, "Dianne Hackborn" <hack...@android.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian  
View profile  
 More options Dec 9 2008, 2:54 pm
From: Ian <heads...@gmail.com>
Date: Tue, 9 Dec 2008 11:54:28 -0800 (PST)
Local: Tues, Dec 9 2008 2:54 pm
Subject: Re: Why do getWidth() and related functions always return 0?
Hi Keith,

Yes, it's a little tricky.  And I certainly don't consider the docs to
be thorough.... more of a work in progress.

Anyhow, the deal is that layout of the contents of a window happens
*after* all the elements are constructed and added to their parent
views.  It has to be this way, because until you know what components
a View contains, and what they contain, and so on, there's no sensible
way you can lay it out.

Bottom line, if you call getWidth() etc. in a constructor, it will
return zero.  The procedure is to create all your view elements in the
constructor, then wait for your View's onSizeChanged() method to be
called -- that's when you first find out your real size, so that's
when you set up the sizes of your GUI elements.

Be aware too that onSizeChanged() is sometimes called with parameters
of zero -- check for this case, and return immediately (so you don't
get a divide by zero when calculating your layout, etc.).  Some time
later it will be called with the real values.

Cheers,

Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Keith Wiley  
View profile  
 More options Dec 9 2008, 4:19 pm
From: Keith Wiley <kbwi...@gmail.com>
Date: Tue, 9 Dec 2008 13:19:07 -0800 (PST)
Local: Tues, Dec 9 2008 4:19 pm
Subject: Re: Why do getWidth() and related functions always return 0?
Thanks, very helpful info.  I'll take it under advisement.

Cheers!

On Dec 9, 11:54 am, Ian <heads...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »