Currently, the Android platform provides two types of animations, one is Tween animation, and the second is Frame animation. For details, please see below:
One type is Tween animation, which means constantly changing the image of the objects in the scene to produce animation effects (rotation, translation, zooming and gradient).
The second category is Frame animation, that is, the pre-made images are played in sequence, similar to the principle of gif images.
There are two ways to implement animations: one uses XML files (files placed in res/anim), and the other is to solve them directly.
1. Transparency control animation effect alpha
<!-- Transparency control animation effectalpha Floating point value: fromAlpha Transparency at the start of the animation toAlpha Transparency at the end of the animation illustrate:0.0 Completely transparent 1.0 Totally opaque The above value is taken0.0-1.0Between floatNumber of data type duration For animation duration Long shape: illustrate:Time in milliseconds --> <alpha android:duration="3000" android:fromAlpha="0.0" android:toAlpha="1.0" />
Code method:
Animation animationAlpha = new AlphaAnimation(0.0f, 1.0f);
(3000);
(animationAlpha);
2. Rotate rotation animation
<!-- rotateRotate animation effect property:interpolator Specify an animation inserter There are three animation inserters: accelerate_decelerate_interpolator accelerate-slow down Animation Insertler accelerate_interpolator accelerate-Animation Insertler decelerate_interpolator slow down-Animation Insertler Others belong to specific animation effects Floating point integer value: fromDegrees The angle of the object at the beginning of the animation toDegrees The angle at which the object rotates at the beginning of the animation Can be greater than360Spend illustrate:当角Spend为negative number——Indicates counterclockwise rotation 当角Spend为Positive number——Indicates clockwise rotation (negative numberfrom——toPositive number:Rotate clockwise negative numberfrom——tonegative number:Rotate counterclockwise Positive numberfrom——toPositive number:Rotate clockwise) pivotX Animate with respect to the objectXThe start position of the coordinates pivotY Animate with respect to the objectYThe start position of the coordinates illustrate:以上两个property值 from0%——100%Medium value 50%For objectsXorYMidpoint position on the direction coordinate Long type: duration For animation duration illustrate:Time in milliseconds --> <rotate android:duration="3000" android:fromDegrees="0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toDegrees="+350" />
Animation animationRotate = new RotateAnimation(0.0f, +350.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
(3000);
(animationRotate);
3. Size expansion animation effect scale
<!-- Size telescopic animation effect scale property:interpolator Specify an animation inserter There are three animation inserters: accelerate_decelerate_interpolator accelerate-slow down Animation Insertler accelerate_interpolator accelerate-Animation Insertler decelerate_interpolator slow down-Animation Insertler Others belong to specific animation effects Floating point value: fromXScale At the beginning of the animation XScaling dimensions on coordinates toXScale At the end of the animation XScaling dimensions on coordinates fromYScale The beginning of the animation Y时Scaling dimensions on coordinates toYScale At the end of the animation YDimensions on coordinates illustrate:以上四种property值 0.0Indicates that it has contracted to no 1.0It means no scaling normally Value is less than1.0Indicates shrinkage Value greater than1.0Indicates enlargement pivotX Animation relative to objectXThe start position of the coordinates pivotY Animation relative to generalsYThe start position of the coordinates illustrate:以上两个property值 from0%-100%Medium value Long shape: duration Animation duration illustrate:Time in milliseconds Boolean value: fillAfter When set totrue,The animation conversion is applied after the animation is finished --> <scale android:duration="700" android:fillAfter="false" android:fromXScale="0.0" android:fromYScale="0.0" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:pivotX="50%" android:pivotY="50%" android:toXScale="1.4" android:toYScale="1.4" />
Code method:
Animation animationScale = new ScaleAnimation(0.0f, 1.4f, 0.0f, 1.4f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); (3000); (animationScale);
4. Translate position to move the effect
<!-- translate Position to move the effect Integer value: fromXDelta At the beginning of the animation XPosition on coordinates toXDelta At the end of the animation XPosition on coordinates fromYDelta At the beginning of the animation YPosition on coordinates toYDlta At the end of the animation YPosition on coordinates Notice:No specifiedfromXTra toXType fromYType toYType when,By default, you are the relative reference Long shape:duration For animation duration Time in milliseconds --> <translate android:duration="2000" android:fromXDelta="30" android:fromYDelta="30" android:toXDelta="-80" android:toYDelta="300" />
Animation animationTranslate = new TranslateAnimation(30.0f, -80.0f, 30.0f, 300.0f);
(3000);
(animationTranslate);
If you use the xml file method, just two lines of code
Animation anim = (activity, .anim_xxx);
(anim);
5. Frame frame animation (file placed in res/drawable)
<!-- The root tag isanimation-list,inoneshotMeaning whether it is only displayed once,Set asfalseWill keep playing animations Under the root tag,passitemTags declare every image in the animation android:duration Indicates the length of time the image used to display --> <animation-list xmlns:andro android:oneshot="true" > <item android:drawable="@drawable/icon_frame1" android:duration="200"> </item> <item android:drawable="@drawable/icon_frame2" android:duration="200"> </item> <item android:drawable="@drawable/icon_frame3" android:duration="200"> </item> <item android:drawable="@drawable/icon_frame4" android:duration="200"> </item> <item android:drawable="@drawable/icon_frame5" android:duration="200"> </item> <item android:drawable="@drawable/icon_frame6" android:duration="50"> </item> </animation-list>xml frame animation usage code:
ivFrame = (ImageView) findViewById(.iv_frame_image); (.anim_frame); animation = (AnimationDrawable) (); (false);//cycle();
The above is all the content for implementing animation effects for Android, I hope everyone likes it.