Android development-animation implementation method
This article describes how to implement animations for Android development. Share it with you for your reference. The specific analysis is as follows:
There are three types of animations:
Frame-by-frame animation, layout animation, and control Animation
Control animation implementation
You can override the applyTransformation (float interpolatedTime, Transformation t) function of Animation to implement Custom Animation effects. In addition, initialize (int width, int height, int parentWidth, int parentHeight) is generally implemented) this is a callback function that tells Animation the size parameter of the target View. Here, you can initialize some related parameters, such as setting the Animation duration, setting the Interpolator, and setting the Animation reference point.
The OPhone calls the applyTransformation function repeatedly during the animation process. The value of interpolatedTime changes every time the parameter is called. The parameter changes from 0 to 1. When this parameter is set to 1, the animation ends. The Transformation parameter is used to obtain the transformed matrix. By changing the matrix, various complex effects can be achieved.
The following is an example of a control Animation:
?
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
Animation anim = new Animation (){ @ Override Protected void applyTransformation (float interpolatedTime, Transformation t ){ If (interpolatedTime = 1 ){ V. setVisibility (View. GONE ); } Else { V. getLayoutParams (). height = initialHeight-(int) (initialHeight * interpolatedTime ); V. requestLayout (); } } @ Override Public boolean willChangeBounds (){ Return true; } }; |
In this example, the height of a view gradually changes from the original height to 0. When the animation ends, the view disappears.
I hope this article will help you design your Android program.