Android basic animation, code build animation

Source: Internet
Author: User

Using code to build Android basic animations, basic animations have the following:

Alphaanimation: Gradient Transparency Animation

Rotateanimation: Rotate Animation

Scaleanimation: Stretch Animation

Translateanimation: Panning Animations


You can define some commonly used animation effects, or you can customize some animations to set aside the parameters.

You can define some combinations of animation effects, such as: from inside to outside. For the combined animation effect, use the basic animation effect to build up.

Use Animationset to add to this collection, so that the animation inside it works together, you can see the unexpected effect.

Code Tool classes

/** * Animation using code design * */public class Animationcodeutils {private static Animation anim;/** * default is: 1. Transparency from 1.0~0, 2. Animation Time 3000 ms 3. Stop at animation end status * * @return gradient transparency animation */public static Alphaanimation alphaanimation1to0 () {alphaanimation alpha = new Alphaanim ation (1.0f, 0.0f); alpha.setduration (+); return alpha;}  /** * default is: 1. Transparency from 0.0~1, 2. Animation time 3000 msec 3. Stop at the end of the animation state * * @return Gradient transparency animation */public static Alphaanimation alphaanimation0to1 () {alphaanimation alpha = new Alphaanimation (0.0f, 1.0f); alpha.setduration (+); return alpha;}            /** * @param fromalpha * Start Transparency (0~1.0) * @param toalpha * End Transparency (0~1.0) * @param durationmillis * Animation Execution Time * @param fillafter * Stop at end of animation * @return */public static alphaanimation Alphaanimationcustom (fl Oat fromalpha,float Toalpha, Long Durationmillis, Boolean fillafter) {alphaanimation alpha = new Alphaanimation (fromalpha , Toalpha); Alpha.setduration (Durationmillis); Alpha.setfillafter (fillafter); return Alpha;} /** * Rotate animation, clockwise 360 default: 1. Angle of rotation: 0~360 2. Relative to its own center position 3. The rotation time is 30004. Do not stay at the end of the animation state * * @return */public static rotateanimation rotateanimation0to360 () {Rotateanim ation rotate = new Rotateanimation (0f, 360f,rotateanimation.relative_to_self, 0.5f,rotateanimation.relative_to_self, 0.5f); rotate.setduration; Rotate.setfillafter (false); return rotate;} /** * Rotate animation, counterclockwise 360 default: 1. Rotation angle: 360-0 2. Relative to its center position 3. The rotation time is 30004. Do not stay at the end of the animation state * * @return */public static rotateanimation rotate Animation360to0 () {rotateanimation rotate = new Rotateanimation (360f, 0f,rotateanimation.relative_to_self, 0.5f, Rotateanimation.relative_to_self, 0.5f); rotate.setduration (+); Rotate.setfillafter (false); return rotate;} /** * * Rotate animation, customize * * @return *//** * @param fromdegrees * Start rotation angle * @param todegrees * End angle * @pa Ram Pivotxtype * x Direction relative position type * @param pivotxvalue * x Direction relative position value * @param pivotytype * y direction relative position Type * @param pivotyvalue * value of relative position in y direction * @param durationmillis * Animation Execution time * @param fillAfter * whether to stay at animation end time * @return */public static rotateanimation rotateanimationcustom (float fromdegrees,float ToD egrees, int pivotxtype, float pivotxvalue, int pivotytype,float pivotyvalue, Long Durationmillis, Boolean fillafter) {Rota Teanimation rotate = new Rotateanimation (fromdegrees, Todegrees,pivotxtype, Pivotxvalue, Pivotytype, PivotYValue); Rotate.setduration (Durationmillis); Rotate.setfillafter (fillafter); return rotate;} /** * Telescopic animation default: Relative to itself, the upper left corner shrinks, from there to none, animation time 3000, does not stay in the animation end state */public static scaleanimation Scaleanimation1to0 () { Scaleanimation scale = new Scaleanimation (1.0f, 0.0f, 1.0f, 0.0f,scaleanimation.relative_to_self, 0f, Scaleanimation.relative_to_self, 0f); scale.setduration (+); Scale.setfillafter (false); return scale;} /** * Scaling Animation default: Relative to oneself, the upper corner to the left to enlarge, from scratch, animation time 3000, do not stay in the end of the animation state */public static Scaleanimation scaleanimation0to1 () { Scaleanimation scale = new Scaleanimation (0.0f, 1.0f, 0.0f, 1.0f,scaleanimation.relative_to_self, 0f, Scaleanimation.relative_to_self, 0f); SCALE.SETDURation (n); Scale.setfillafter (false); return scale;} /** * Telescopic Animation *//** * @param fromX * x Direction start zoom angle (0-1) 0 is not displayed, 1 is all display * @param toX * x Direction end Zoom Angle (0-1) 0 is not displayed, 1 is Show all * @param fromY * y direction start zoom angle (0-1) 0 is not displayed, 1 is all display * @param toY * y direction End zoom angle (0-1) 0 is not displayed, 1 is all display * @ Param pivotxtype * x-direction relative type * @param pivotxvalue * x-direction Relative value * @param pivotytype * y-direction opposite type * @param pivotyvalue * y-direction relative value * @param durationmillis * Animation Execution time * @param fillafter * Stop  Left in the end of the animation state * @return */public static scaleanimation scaleanimationcustom (float FromX, float tox,float FromY, float toY, int Pivotxtype, float pivotxvalue,int pivotytype, float pivotyvalue, long Durationmillis,boolean fillafter) {ScaleAnimation Scale = new Scaleanimation (FromX, ToX, FromY, Toy,pivotxtype, Pivotxvalue, Pivotytype, Pivotyvalue); Scale.setduration ( Durationmillis); Scale.setfillafter (fillafter); return scale;} /** * Panning Animation: Panning from left to right * * @return */PUBLIC static Translateanimation translateanimationlefttoright () {translateanimation translate = new Translateanimation ( Translateanimation.relative_to_self, 0.0f,translateanimation.relative_to_self, 1.0f,TranslateAnimation.RELATIVE_ To_self, 0.0f,translateanimation.relative_to_self, 0.0f); translate.setduration (+); Translate.setfillafter ( FALSE); return translate;} /** * Panning Animation: Panning from right to left * * @return */public static translateanimation Translateanimationrighttoleft () {translateanimation tra Nslate = new Translateanimation (translateanimation.relative_to_self, 1.0f,translateanimation.relative_to_self, 0.0f , Translateanimation.relative_to_self, 0.0f,translateanimation.relative_to_self, 0.0f); Translate.setDuration (3000 ); Translate.setfillafter (false); return translate;} /** * Pan Animation: Custom * * @return *//** * @param fromxtype * x direction start translation Relative type * @param fromxvalue * x direction start translation relative value * @param toxtype * x direction end translation Relative type * @param toxvalue * x direction end Translation Relative value * @param fromytype * y SquareStart translation Relative type * @param fromyvalue * y direction begin translation Relative value * @param toytype * y direction end translation Relative type * @param toyvalue *  End translation relative value in y direction * @param durationmillis * Animation Execution time * @param fillafter * is stuck in the end of animation * @return */public static translateanimation translateanimationcustom (int fromxtype,float fromxvalue, int toxtype, float toxvalue, int from Ytype,float fromyvalue, int toytype, float toyvalue, long Durationmillis,boolean fillafter) {translateanimation translate = new Translateanimation (Fromxtype,fromxvalue, Toxtype, Toxvalue, Fromytype, Fromyvalue, Toytype,toyvalue); Translate.setduration (Durationmillis); Translate.setfillafter (fillafter); return translate;} /** * Animation collection: gradient-zoom-rotate, effect, rotate from inside to zoom in * * @return */public static Animation Animationset () {Animationset aniset = new Animation Set (TRUE);//True indicates a function together Aniset.addanimation (Alphaanimation0to1 ()); Aniset.addanimation ( Animationcodeutils.scaleanimationcustom (0f, 1f, 0f,1f, Scaleanimation.relative_to_self, 0.5f,ScaleAnimation.Relative_to_self, 0.5f, Aniset.addanimation, false)); rotateanimation0to360 (); return aniset;}} 


SOURCE Download: http://download.csdn.net/detail/forwardyzk/8317823
Animation:


Android basic animation, code build 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.