Thursday, August 25, 2011

[android-developers] Re: how to get the view size after orientation changed

On Aug 23, 10:05 am, Dianne Hackborn <hack...@android.com> wrote:
> You need to participate in the view hierarchy as a layout manager, do get
> the onSizeChanged() calls and such.

Since it's come up, it's actually been a thorn in my side to have to
"be" a layout manager to know something simple such as the size of a
view when it's changed size. It comes up again and again for some
things I do. It would be a huge save of time and effort if I could
just register a listener on a View to know when its onSizeChanged
method has been called.

For example, if I want to place an overlay on some arbitrary view as a
callout or popup, I need to know its size and position the moment
those things are known. I can't do it during any of the activity
lifecycle methods because layout is a different stream of computation
than the lifecycle. Same thing goes if I need to compute coordinates
for an animation that happens at activity startup rather than on UI
events.

I've seen people hack up ugly polling looping to find out when layout
completes! And it seems like huge waste of time just to implement a
custom View or LayoutManager just to make this work. I hope that I'm
just going about this the wrong way and that there is a more elegant
solution. In the absence of that, having a hook into a view's
onSizeChanged would be a huge win, IMO.

Doug


--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment