What is the best practice to start an animation di

2019-08-23 09:47发布

问题:

I'm looking for a best practice pattern which helps me with the following problem.

I want to start an animation as soon as the layout of an Activity got rendered to the screen. As my animation depends of the original width and height of a View in the layout I have to start the animation some time after onResume() has finished, so I could retrieve the height and widht of the view to prepare the animation.

But I'm wondering how to trigger the animation after the layout was rendered? Are there any events I could hook into? What is the best practice for this problem?

回答1:

ViewTreeObserver.OnGlobalLayoutListener should help. Also ViewTreeObserver.OnPreDrawListener.

I had to deal with this problem in this code android-sliding-menu-demo.