tweened Animation Tween

Source: Internet
Author: User

1. Transparency Gradient Animation (alphaanimation)

1) Pure Code implementation

Animation Animation = new Alphaanimation (1f,0.1f);

Parameter 1: Starting transparency;

Parameter 2: target transparency;

//implementing the Gradient featureAnimationset Aset =NewAnimationset (true); Alphaanimation Alpha=NewAlphaanimation (1,0);//fully displayed -//fully TransparentAlpha.setduration ( the);//3 seconds to complete the animationAset.addanimation (Alpha);//Add animationsMainactivity. This. Img.startanimation (Aset);//Start Animation

2) XML file implementation (new XML under new Anim file under Res file)

Xml:

<SetXmlns:android="http://schemas.android.com/apk/res/android"><Alpha Android:repeatmode="Restart"Android:repeatcount="3"android:duration=" -"Android:fromalpha="1"Android:toalpha="0"> </alpha></Set>

Java:

Animation anim = animationutils.loadanimation (mainactivity.  this,                    r.anim.alpha);            Mainactivity.  This // Start Animation

2. Rotate

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: End angle of rotation

Parameter 3: X-axis value reference method for the center of rotation

Parameter 4: The value of the center point x-axis

Parameter 5: The y-axis value reference method of the center of rotation

Parameter 6: Value of the y-axis of the center point

1) Pure Code implementation

Animationset RSet =NewAnimationset (true); Rotateanimation Rotate=NewRotateanimation (0,360,//0~360度animation.relative_to_parent,0.5f,//x-axis start positionanimation.relative_to_parent,0.0f);//y-axis move positionRotate.setduration (3000);//3 seconds to complete the animationRset.addanimation (rotate);//Add animationsmainactivity. This. Image.startanimation (RSet);//Start Animation

2) XML implementation

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <rotate        android:fromdegrees= "0.0"        android:todegrees= "+360.0"         Android:pivotx= "50%p"        android:pivoty= "0%p"        android:duration= "/></" Set>

3. Zooming

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 indicates original size)

Parameter 2:x direction stop size (0.2f = 0.2 times times the original)

Parameter 3:y direction start size (1f indicates original size)

Parameter 4:y direction stop size (0.2f = 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 the original)

Parameter 7: Zoom center point y-axis value reference method

Parameter 8: The value of the y-axis of the center point (0.5f means 0.5 times times the original)

1) Code implementation

//Implementing the Zoom functionAnimationset Sset =NewAnimationset (true); Scaleanimation Scale=NewScaleanimation (1, 0.0f, 1, 0.0f, Animation.relative_to_self,0.5f, Animation.relative_to_self,0.5f); Scale.setduration (3000);//3 seconds to complete the animationSset.addanimation (scale);//Add animationsMainactivity. This. Image.startanimation (Sset);//Start Animation

2) XML implementation

<set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <scale        Android:fromxscale = "1.0"        android:toxscale= "0.0"        android:fromyscale= "1.0"        Android:toyscale = "0.0"        android:pivotx= "50%"        android:pivoty= "50%"        android: Startoffset= "        android:repeatcount" = "3"        android:duration= "+"/> </set>

4. Panning Animations

Animation Animation = new Translateanimation (0,50,0,50);

The starting position of the 1:X axis of the parameter

Parameter 2:x the end position of the axis

The starting position of the 3:y axis of the parameter

Parameter 4:y the end position of the axis

1) Code implementation

//Implement MobileAnimationset Tset =NewAnimationset (true); Translateanimation Tran=Newtranslateanimation (animation.relative_to_self,0.0f,//x-axis start positionanimation.relative_to_self,0.5f,//end position of x-axis movementanimation.relative_to_self,0.0f,//y-axis start positionanimation.relative_to_self,0.5f);//y-axis move positionTran.setduration (3000);//3 seconds to complete the animationTset.addanimation (Tran);//Add animationsMainactivity. This. Image.startanimation (Tset);//Start Animation

2) XML implementation

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" >    <translate        android:fromxdelta= "0.0"        android:toxdelta= "50%"         Android:fromydelta= "0.0"        android:toydelta= "150%"        android:duration= "/>" </set>

5. Mixed animations

1) Code implementation

Animationset Tset =NewAnimationset (true); Aset=NewAnimationset (true); Alphaanimation Alph=NewAlphaanimation (0, 1); Alph.setrepeatcount (3); Alph.setduration (5000);                                 Aset.addanimation (Alph); Translateanimation Tran=Newtranslateanimation (animation.relative_to_self,0.0f,//x-axis start positionanimation.relative_to_self,0.5f,//end position of x-axis movementanimation.relative_to_self,0.0f,//y-axis start positionanimation.relative_to_self,0.5f);//y-axis move positionTran.setduration (3000);//3 seconds to complete the animationtset.addanimation (Alph);//Add animationsTset.addanimation (Tran);//Add animationsmainactivity. This. Image.startanimation (Tset);//Start Animation

2) XML Configuration implementation

<?xml version= "1.0" encoding= "Utf-8"? ><set xmlns:android= "Http://schemas.android.com/apk/res/android" > <Translate Android:fromxdelta= "0.0"Android:toxdelta= "50%"Android:fromydelta= "0.0"Android:toydelta= "150%"android:duration= "/>" <Scale Android:fromxscale= "1.0"Android:toxscale= "0.0"Android:fromyscale= "1.0"Android:toyscale= "0.0"Android:pivotx= "50%"Android:pivoty= "50%"Android:startoffset= "100"Android:repeatcount= "3"android:duration= "/></set>"

tweened Animation Tween

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.