When are View.getWidth and getHeight values valid?

Showing 1-3 of 3 messages
When are View.getWidth and getHeight values valid? revcom 3/4/08 1:47 PM
Hi there,

When an activity starts the main content view is selected in
onCreate(0 using "setContentView(R.layout.main);" or similar.
Obviously at this point the specified view (and its nested views) have
not yet been laid out.

Is there a specific Activity.onXXX() override where you can guarantee
all nested views have been laid out and their getWidth() and
getHeight() methods will return the correct values?

Thanks...

Robert
Re: When are View.getWidth and getHeight values valid? joebowbeer 3/4/08 2:31 PM
The view's size is assigned when view.onSizeChanged is called with
oldw = oldh = 0.

Assuming your view is visible, its size has been assigned by the time
the activity's window receives focus.  That is, when
activity.onWindowFocusChanged is called with hasFocus = true.

The sequence is roughly:

  view.onFinishInflate
  view.onMeasure
  view.onSizeChanged(width, height, 0, 0)
  view.onLayout
  activity.onWindowFocusChanged(true)

--
Joe Bowbeer
Re: When are View.getWidth and getHeight values valid? revcom 3/4/08 2:36 PM
Thanks Joe,

Robert