Interpolator and Animationset of Android animations

Source: Internet
Author: User

If you are developing a composite animation in Android, you need to use the class Animationset class to take advantage of its Add method to add animations or use the layout file set to add multiple animations. But they started the animation at the same time.

1 XML Code2 <?XML version= "1.0" encoding= "Utf-8"?>3 <setxmlns:android= "Http:android="the Res=""apk=""schemas.android.com="">  4  <Translate5     Android:toxdelta= "100%p" 6 Android:fromxdelta= "0" 7 android:duration= "+">    8     </Alpha>9 </Translate>Ten </setxmlns:android= "http:>

1 //applying multiple animations via Animationset2 //Animationset provides a mechanism for combining multiple animations into one, and sets the timing relationships of the animations in the group, such as simultaneous playback, sequential playback, and so on. 3 //The following example applies 5 animations at a time:4 //play anim1;5 //simultaneous playback of ANIM2,ANIM3,ANIM4;6 //play ANIM5. 7Animatorset bouncer =NewAnimatorset ();8 Bouncer.play (ANIM1). before (anim2);9 Bouncer.play (ANIM2). with (ANIM3);Ten Bouncer.play (ANIM2). with (ANIM4) One Bouncer.play (ANIM5). After (amin2); AAnimatorset.start ();

Animationset can join animation and set Animationset to be valid for all animation to join.

1Animationset anim=NewAnimationset (true); 2Alphaanimation a=NewAlphaanimation (1,0); 3Rotateanimation ra=NewRotateanimation (0, 720, animation.relative_to_self,0.5f, animation.relative_to_self,0.5f); 4 Anim.addanimation (a);5 anim.addanimation (RA);6Anim.setduration (3000); 7Anim.setstartoffset (1000); 8 iv.startanimation (anim);9  TenAnimationset anim=NewAnimationset (true); OneAlphaanimation a=NewAlphaanimation (1,0); ARotateanimation ra=NewRotateanimation (0, 720, animation.relative_to_self,0.5f, animation.relative_to_self,0.5f); - Anim.addanimation (a); - anim.addanimation (RA); theAnim.setduration (3000); -Anim.setstartoffset (1000); -Iv.startanimation (ANIM);

Multiple animation can be defined in the XML file so that multiple animation can be run together

1 <?XML version= "1.0" encoding= "Utf-8"?> 2  <Setxmlns:android= "Http://schemas.android.com/apk/res/android" 3 Android:interpolator= "@android: Anim/accelerate_interpolator" 4 Android:shareinterpolator= "true" 5      > 6      <Alpha7          Android:fromalpha= "1.0" 8 Android:toalpha= "0.0" 9 Android:startoffset= "$" Ten android:duration= " the"  One              />  A      <Rotate -          android:fromdegrees= "0"  - android:todegrees= "The "  the Android:pivotx= "50%"  - Android:pivoty= "50%"  - android:duration= " the"  -      />  +    -  </Set> 

1 <?XML version= "1.0" encoding= "Utf-8"?>2  <Setxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:interpolator= "@android: Anim/accelerate_interpolator"4 Android:shareinterpolator= "true"5      >6      <Alpha7          Android:fromalpha= "1.0"8 Android:toalpha= "0.0"9 Android:startoffset= "$"Ten android:duration= " the" One              /> A      <Rotate -          android:fromdegrees= "0" - android:todegrees= "The " the Android:pivotx= "50%" - Android:pivoty= "50%" - android:duration= " the" -      /> +   - </Set>

Interpolator can define the speed of animation playback

Defining interpolator in an XML file

Android:interpolator= "@android: Anim/accelerate_interpolator" android:shareinterpolator= "true"

  

So all the animation share a interpolator.

Set the following code in code

Anim.setinterpolator (new accelerateinterpolator ());

Pass in new Animationset True then all animation shared Interpolator

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.