2

I'd like to get the height of a linearlayout. I found more information in this answer

View.getWidth()/View.getHeight() won't give you a meaningful answer until the view has been measured.

How will I know that view has been measured? Is there some event for it?

UPD:

Solution for me is to get layout's height in overriden onWindowFocusChanged()

Community
  • 1
  • 1
Tima
  • 12,765
  • 23
  • 82
  • 125

1 Answers1

1

There currently aren't any events that will fire that specifically tell you the size of a view has changed. As suggested in the threads you pointed to, you can check for when the view has focus, and assume that once it has focus, it has width/height greater than 0.

Another way: There's an onSizeChanged method which you can override in a subclass and use to do something when non-zero values come in. Obviously, be sure to call super.onSizeChanged(...).

Alexander Lucas
  • 22,171
  • 3
  • 46
  • 43
  • "assume that once it has focus, it has width/height greater than 0" .. may be it's not so intelligent answer, but should I do it within a while loop?! ... i try tomorrow your second suggestion ... android thing are too complicated – Tima Nov 01 '10 at 20:58
  • Thank you for your answer :) it was enough for me to get height in onWindowFocusChanged() :) – Tima Nov 02 '10 at 09:51