1. Motion Tween View Animation (Tween Animation) 1.1-bit Moving picture XML definition:
<translate xmlns:android= "http://schemas.android.com/apk/res/android" android:fromxdelta= "0" Android : Toxdelta= " android:fromydelta=" 100%p " android:toydelta=" 0 " android:duration="/> " <!--The horizontal axis of the start position of the Fromxdelta animation Toxdelta The horizontal axis of the end position of the animation Fromydelta the start position of the animation Toydelta the duration of the ordinate duration animation for the end position of the animation 100%p the position of its own length--
Code implementation:
Animation Animation = new Translateanimation (0,50,0,50), parameter 1:x axis start position parameter 2:x axis end position Parameter 3: The start position parameter of the y-axis 4:y The end position of the axis relative to the origin of the original position (the upper-right corner of the picture is 0,0), if you do not want to use this point as the reference point, you can use other constructs translateanimation (Fromxtype, Fromxvalue, Toxtype , Toxvalue, Fromytype, Fromyvalue, Toytype, toyvalue) parameter 1, parameter 3, parameter 5, parameter 7 is the way to set the reference point
1.2 Rotation animation XML definition:
<rotate xmlns:android= "http://schemas.android.com/apk/res/android" android:fromdegrees= "0" android: Todegrees= "android:duration=" /> <!-- Fromdegrees: Indicates the starting angle of rotation todegrees: Represents the end angle of the rotation duration animation duration from<to: Clockwise rotation from>to: counterclockwise
Code implementation:
Animation Animation = new Rotateanimation (360,0,animation.relative_to_self,0.5f,animation.relative_to_self, 0.5f); Parameter 1: Starting angle of rotation parameter 2: rotation of the end angle Parameter 3: Rotation Center x axis value Reference mode parameter 4: center point x Axis value parameter 5: Rotation Center Y axis Value Reference mode parameter 6: Center point Y axis value
1.3 Transparency Animation XML definition:
<alpha xmlns:android= "http://schemas.android.com/apk/res/android" android:fromalpha= "1.0" android: Toalpha= "0.1" android:duration= "$"/> <!-- Fromalpha: Starting transparency toalpha: Ending transparency 1.0 means full opacity 0.0 means full transparency- -
Code implementation:
Animation Animation = new Alphaanimation (1f,0.1f), parameter 1: Starting transparency, Parameter 2: target transparency;
1.4 Scaling Animation XML definition:
<scale xmlns:android= "http://schemas.android.com/apk/res/android" android:fromxscale= "0.5" android: Toxscale= "1.0" android:fromyscale= "0.5" android:toyscale= "1.0" android:pivotx= "50%" android: Pivoty= "50%" android:duration= "x"/> <!-- Fromxscale: Represents the starting scale for scaling along the axis Toxscale: Represents the end scale scaled along the x-axis Fromyscale: Represents the starting scale of scaling along the y-axis Toyscale: Represents the end scale scaled along the y-axis 1.0 indicates that the original size 50% represents the center of the picture
Code implementation:
Animation Animation = new Scaleanimation (1f,0.2f,1f,0.2f,animation.relative_to_self,0.5f,animation.relative_ to_self,0.5f); Parameter 1:x direction start size (1f for original size) parameter 2:x direction end size (0.2f for original 0.2 times times) parameter 3:y direction start size (1f for original size) parameter 4:y direction stop size (0.2f indicates 0.2 times times the original) Parameter 5: Scaling center point x axis Value reference method parameter 6: The value of the center point x axis (0.5f = 0.5 times times relative to the original) parameter 7: Zoom center point Y axis Value reference method parameter 8: The value of the center point Y axis (0.5f is relative to the original image 0.5 times times) ( Note: Reference method: Animation.relative_to_self: Self animation.relative_to_parent: Parent control Animation.absolute: Absolute)
1.5 Common attributes
Android:duration (play time) Android:repeatcount: Repeat the default value is 0 for rotation 1 times, the value is 1 or infinite, indicating that the animation never stops Android:repeatmode: set a repeating mode. The default is restart. (When the value of RepeatCount is greater than 0 or infinite is valid) is set to reverse, which means that an even number of times the animation will be animated in the direction opposite to the direction defined by the animation file. Corresponding Code method: Animation.setduration (Long Durationmillis) animation.setrepeatcount (int repeatcount) Animation.setrepeatmode (int repeatmode) android:interpolator (animated renderer) Accelerate_interpolator (animation accelerator) makes the animation the slowest at the beginning, Then gradually accelerate the Decelerate_interpolator (animation reducer) to make the animation at the beginning of the fastest, and then gradually slow down accelerate_decelerate_interpolator (animation acceleration reducer) slow to fast (middle position fastest) to slow Anticipate_interpolator (pre-animation counter) moves in the opposite direction of the animation movement and then moves along the set animation Overshoot_interpolator (post-animation counter) and then slowly changes to the destination value Anticipate_overshoot_interpolator (the animated double-counter) moves a little in the opposite direction of the animation, then moves to the end point in the set direction and continues to move a little and then bounces back to the final set position bounce_interpolator ( Animation bounce) Fast to the destination value will jump Cycle_interpolator (animation circulator) animation cycle a certain number of times linear_interpolator (animation constant) linear uniform change Overshoot_interpolator (animation reducer) Quickly reach the end and go beyond one step to the end. Use: Android:interpolator= "@android: Anim/accelerate_interpolator" Corresponding code method: Animation.setinterPolator (context context, int ResID)//r.anim.accelerate_interpolatoranimation.setinterpolator (interpolator i) Timeinterpolator an interface that allows you to customize the Interpolator, the following are implementations of this interface accelerateinterpolator acceleration, beginning with slow intermediate acceleration decelerateinte Rpolator slow down, start fast and then slow down acceleratedecelerateinterolator first accelerate, slow down, start to end slowly, intermediate acceleration anticipateinterpolator reverse, first in the opposite direction Change a period of re-acceleration play anticipateovershootinterpolator reverse plus transcendence, first change in the opposite direction, and then speed up the play, will exceed the target value and then slowly move to the destination value Bounceinterpolator jump, to the destination value Will jump, such as the destination value 100, the following value may be 85,77,70,80,90,100 Cycleinterpolator Loop, the animation loop a certain number of times, the value is changed to a sine function: Math.sin (2 * Mcycles * Math.PI * input) Linearinterpolator linear, linear uniform change overshottinterpolator transcendence, finally exceeding the target value and then slowly changing to the destination value
2. Composition Animation 2.1AnimationSetxml definition:
<set xmlns:android= "http://schemas.android.com/apk/res/android" android:interpolator= "@android: anim/ Accelerate_decelerate_interpolator " android:shareinterpolator=" true "> <scale .../> <rotate ... /> <translate ... /> <alpha ... /> <!-- Shareinterpolator: Does the animation effect share a interpolator do not share settings android:shareinterpolator= "false", Each animation effect adds interpolator itself. --></set>
Code implementation:
Alphaanimation alpha=new alphaanimation (0, 1); Alpha.setduration (1000); Animationset animset = new Animationset (false); animset.addanimation (Alpha);
2.2 Layoutanimation (Gridlayoutanimationcontroller)
XML definition:
<?xml version= "1.0" encoding= "Utf-8"?> <layoutanimation xmlns:android= "http// Schemas.android.com/apk/res/android " android:delay=" 0.5 " android:animationorder=" normal " android: animation= "@anim/alpha" /> <!-- delay: How much delay starts playing--
Code implementation:
Alphaanimation alpha=new alphaanimation (0, 1); Alpha.setduration (+); Layoutanimationcontroller lac=new Layoutanimationcontroller (alpha); Lac.setorder (layoutanimationcontroller.order_normal); Listview.setlayoutanimation (LAC); Layoutanimationcontroller.order_normal; sequential display of layoutanimationcontroller.order_reverse; Anti-display layoutanimationcontroller.order_random //random display
Use:
<listview android:id= "@+id/listview1" android:layout_width= "fill_parent" android:layout_height= "Wrap_content" android:layoutanimation= "@anim/layoutanimation"/>
2. Frame-by-frames animation drawable Animation (frame Animation)
XML definition:
<animation-list xmlns:android= "http://schemas.android.com/apk/res/android" android:oneshot= "true" > <item android:drawable= "@drawable/girl1" android:duration= "/> <item android:drawable= " @ Drawable/girl2 "android:duration="/> <item android:drawable= "@drawable/girl3" android:duration= "100 "/> <!--
Code implementation:
Animationdrawable anim = new animationdrawable (); for (int i = 1; I <= 3; i++) { int id = getresources (). Getidentifier ("Girl" + I, "drawable", Getpackagename ());
drawable drawable = Getresources (). getdrawable (ID); Anim.addframe (drawable, 100);
Play:
View.setbackgroundresource (r.anim.frame); Animationdrawable Anim = (animationdrawable) image.getbackground (); Anim.start (); Note: If you want the activity to play in the beginning, please put it in the Onwindowfocuschanged method.
Android Animation Summary