You cannot do that from onCreate(), you have to wait for the first layout to happen. Besides, you don't need to hard code values in animation since you can use values relative to a view, or its parent. For instance, in XML, you can use 50%p to say "50% of the size of the parent" or 40% to say "40% of the size of the animated view."
On Thu, Jun 11, 2009 at 4:57 PM, Beth Mezias<[email protected]> wrote: > Hi there, > Can a layout expert offer insight here? I have an animation in a lovely > LinearLayout ViewGroup object that I get into Java from the XML using > findViewById. It's working great most of the time. However, my first call > to the animate function at the end of onCreate measures the width of this > ViewGroup to be zero. What am I missing? The same object will return > correct width measurements later in the thread of execution. How can I get > the correct measure from onCreate? > Because of this behavior I have hard-coded values into my application for > the Center X which might work nicely on the current HTC devices and then > blow up later, or it might look bad in Europe on devices with different > screen sizes. I tried a number of things to solve this (force layout, varied > animation cache persistence, getMeasuredWidth instead of getWidth, > invalidate on the ViewGroup and parent). The layout and the component's > measurements should be the same for onCreate as it is in another method in > the Activity that responds to touch input from the user. Also note that if > I navigate in the app to another activity, change orientation, and then > return to the first activity, this scenario also causes the ViewGroup's > getWidth command to be zero. That is why I assume the issue is related to > onCreate. > How do I get the correct measure of a (linearlayout) component when > executing from onCreate? Is there something in the window's drawing > sequence that I need to workaround? > Any tips or suggestions are most welcome. > Regards, > Beth > > > -- Romain Guy Android framework engineer [email protected] 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 received this message because you are subscribed to the Google Groups "Android Beginners" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-beginners?hl=en -~----------~----~----~----~------~----~------~--~---

