The animtion of Android simple animation

Source: Internet
Author: User

Android Simple animation effects are available in the Animtion Class 1. animate in XML; 2. Animate in Java code.

Animation-related properties

Table I: Set properties
Name Property Note
Android:shareinterpolator Whether to share the insertion device When sharing, four child nodes are used with one insert
Android:interpolator Specifies the insertion of an animation Using System resources
Android:fillenabled
when set to true, the Fillafter and fill Befroe will be true, ignoring the two properties of Fillbefore and Fillafter
Android:fillafter Whether the animation conversion is applied after the animation is finished Boolean
Android:fillbefore Whether the animation conversion is applied before the animation starts Boolean
Android:repeatmode Repeating mode "Restart" = start from scratch or "reverse" = start at the end
Android:repeatcount Number of repetitions Integer-1 for Infinite loops
Android:duration Animation duration Integer
Android:startoffset Animation interval (dwell time before animation execution) Long
Android:zadjustment Defines the transformation of the animation Z order [Normal] or [top] or [bottom]
Android:detachwallpaper Unknown Boolean


Here is a detailed explanation of the Android:interpolator animation Insert property (animation speed effect).

[Email protected]:anim/accelerate_decelerate_interpolator: First speed up and then slow down

[Email Protected]:anim/accelerate_interpolator: accelerating

[Email Protected]:anim/decelerate_interpolator: deceleration

[Email Protected]:anim/anticipate_interpolator: Move the animation in the opposite direction and move the trajectory along the set animation.


5.anticipate_overshoot_interpolator: Move a little in the opposite direction of the animation, then move to the end point in the set direction and move on a little bit and then bounce back to the final set position. Such as:


[Email protected]:anim/bounce_interpolator: Animation moves to the end there will be a few rebound effect, and finally stop in the set position.

[Email Protected]:anim/cycle_interpolator: Animation period movement.

[Email Protected]:anim/linear_interpolator: The animation is moving at a constant speed.

[Email Protected]:anim/overshoot_interpolator: The animation to the last position will move in the opposite direction a little.



Interpolator Object Resource ID Functional Role
Acceleratedecelerateinterpolator @android: Anim/accelerate_decelerate_interpolator Accelerate and decelerate first.
Accelerateinterpolator @android: Anim/accelerate_interpolator Accelerated
Anticipateinterpolator @android: Anim/anticipate_interpolator Take a small step back and speed it up.
Anticipateovershootinterpolator @android: Anim/anticipate_overshoot_interpolator A small step beyond the finish line on the last, and then back to the end.
Bounceinterpolator @android: Anim/bounce_interpolator Final stage Pinball effect
Cycleinterpolator @android: Anim/cycle_interpolator Periodic motion
Decelerateinterpolator @android: Anim/decelerate_interpolator Slowdown
Linearinterpolator @android: Anim/linear_interpolator Uniform
Overshootinterpolator @android: Anim/overshoot_interpolator Get to the finish line quickly and go beyond one step to the end
about modifying the properties of an animation insert: Click the link to open it


Table II: Alpha
Name Property Note
Android:toalpha Transparency at the end of the animation float [0,1] 0 means fully transparent 1 means completely opaque
Android:duration Animation duration Integer
Android:fromalpha Transparency at the beginning of the animation float [0,1] 0 means fully transparent 1 means completely opaque



Table III: Scale
Name Property Note
Android:fromxscale The scaling dimensions on the x-coordinate when the animation starts float,0.0 means no, 1.0 indicates normal no stretch, less than 1 means contraction, greater than 1
Android:toxscale Stretch size on x-coordinate at end of animation Ditto
Android:fromyscale The scaling dimension on the y-coordinate when the animation starts Ditto
Android:toyscale Stretch dimensions on the y-coordinate at the end of the animation Ditto
Android:pivotx The start position of the animation relative to the X of the object [0%,100%],50% indicates the middle
Android:pivoty The start position of the animation relative to the Y of the object 0%,100%],50% represents the middle
Android:duration Same set Same set

Table IV: TRANSLATE
Name Property Note
Android:fromxdelta The position of the x-coordinate at the start of the animation Integer defaults to self-referential
Android:toxdelta The position of the x-coordinate at the end of the animation Integer defaults to self-referential
Android:fromydelta Position on the y-coordinate when the animation starts Integer defaults to self-referential
Android:toydelta Position at the end of the animation at the y-coordinate Integer defaults to self-referential


Table V: ROTATE
Name Property Note
Android:fromdegrees When the animation starts, the angle of the object Negative: counterclockwise rotation, positive: clockwise rotation
Android:todegrees The angle of the object at the end of the animation (can be greater than 360 degrees) Ditto
Android:pivotx The start position of the animation relative to the X of the object [0%,100%],50% indicates the middle
Android:pivoty The start position of the animation relative to the Y of the object [0%,100%],50% indicates the middle


One.. XML Implementation Alpha:

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    >    <alpha        android:duration= "android:fromalpha="        0 "        android:repeatcount=" 3 "// The number of times the animation repeats        android:repeatmode= "reverse"//Animation repeat mode  reverse: Reverse, that is, play the animation from the last frame;  restart: order, play the animation        from the beginning Android:toalpha= "1.0"/></set>

A few noteworthy places: if you need to let the animation set android:fillafter= "true"
Android:fillbefore= the property of "false" must be attribute this is only valid under <set>. For example, the valid setting is this
<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:fillafter= "true"   >    <alpha        android:duration= "$"        android:fromalpha= "0"                android:repeatcount= "3"        android:repeatmode= "reverse"        android:toalpha= "1.0"/></set>
Then the animation above will stay on the last frame.


Two. Code implementation alpha

Animation anim = new Alphaanimation (0f, 1.0f); anim.setduration (+); Anim.setrepeatcount (Animation.infinite); Anim.setrepeatmode (Animation.restart);


Three. XML Implementation scale

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:fillafter= "true"    android:interpolator= "@android: Anim/decelerate_interpolator" > <!-- The screen stays at the last frame-    >    <scale        android:duration= "        $" android:fromxscale= "0.5"        android: fromyscale= "0.5"        android:pivotx= "50.0%" > <!--the position at which the animation starts relative to the space X coordinate 50. 0% means to scale the animation from the center of the space--        android:pivoty= "50.0%"        android:repeatcount= "3"        android:repeatmode= " Reverse "        android:toxscale=" 1.0 "        android:toyscale=" 1.0 "         />    </scale></set>

four. Code implementation Scale
Animation anim1 = new Scaleanimation (0.5f, 1.0f, 0.5f, 1.0f, 0.5f, 0.5f); anim1.setduration (in); Anim1.setrepeatcount (3 ); Anim1.setrepeatmode (Animation.reverse); Anim1.setinterpolator (this, interpolator.accelerate_decelerate); Anim1.setfillafter (TRUE);

Five. XML Implementation stranslate

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:interpolator= "@android: Anim/decelerate_interpolator"    android:fillafter= "true" >    < Translate        android:duration= "android:fromxdelta="        0 "        android:fromydelta=" 0 "        android: Toxdelta= "0"        android:toydelta= "/></set>"


Six code implementation stranslate

Animation animtranlate = new Translateanimation (0, 0, 0, N); animtranlate.setduration (2000); Animtranlate.setfillafter (True); Animtranlate.setinterpolator (this, interpolator.bounce); Text.startanimation ( Animtranlate);


Seven. XML implementation rotate

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:fillafter= "true"    android:interpolator= "@android: Anim/accelerate_decelerate_interpolator" >    <rotate        android:duration= "android:fromdegrees="        0 "        android:pivotx=" 50% "        android: Pivoty= "50%"        android:todegrees= "180"//negative is counterclockwise, positive clockwise.
/></set>
Eight. Code implementation rotate

Animation animrotate = new Rotateanimation (0f, 360f,animation.relative_to_self, 0.5f, animation.relative_to_self,0.5f ); Animrotate.setduration (Animrotate.setinterpolator); (this, interpolator.bounce); Animrotate.setfillafter ( true); <span style= "White-space:pre" >animrotate.setstartoffset (); </span>// Duration of text.startanimation (animrotate) before animation execution;

Nine. The implementation of the combined animation

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android"    android:duration= "android:fillafter="    true "    android:interpolator=" @android: Anim/accelerate_ Decelerate_interpolator ">    <alpha        android:fromalpha=" 0 "        android:toalpha=" 1.0 "/>    < Scale        android:fromxscale= "0"        android:fromyscale= "0"        android:pivotx= "50%"        android:pivoty= "50%"        android:toxscale= "1.0"        android:toyscale= "1.0"/></set>


10. The code implements the combination animation

Animation anim1 = new Scaleanimation (0.5f, 1.0f, 0.5f, 1.0f, 0.5f, 0.5f); anim1.setduration (in); Anim1.setrepeatcount (3 ); Anim1.setrepeatmode (Animation.reverse); Anim1.setinterpolator (this, interpolator.accelerate_decelerate); Anim1.setfillafter (TRUE);//Text.setanimation (ANIM1); Animation animtranlate = new Translateanimation (0, 0, 0, N); animtranlate.setduration (2000); Animtranlate.setfillafter (True); Animtranlate.setinterpolator (this, interpolator.bounce);//Text.startanimation ( Animtranlate); Animation animrotate = new Rotateanimation (0f, 360f,animation.relative_to_self, 0.5f, animation.relative_to_self,0.5f ); Animrotate.setduration (Animrotate.setinterpolator); (this, interpolator.bounce); Animrotate.setfillafter ( true);//Text.startanimation (animrotate); Animationset animationset = new Animationset (true); Animationset.addanimation (animrotate); animationset.addanimation (animtranlate); animationset.addanimation (ANIM1); text.startanimation (Animationset);

End!

The animtion of Android simple animation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.