The AnimationSet can be added to the Animation, and the setting of the Animation set is effective for all animations added.
[Java]
AnimationSet anim = new AnimationSet (true );
AlphaAnimation a = new AlphaAnimation (1, 0 );
RotateAnimation ra = new RotateAnimation (0,720, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
Anim. addAnimation ();
Anim. addAnimation (ra );
Anim. setDuration (3000 );
Anim. setStartOffset (1000 );
Iv. startAnimation (anim );
AnimationSet anim = new AnimationSet (true );
AlphaAnimation a = new AlphaAnimation (1, 0 );
RotateAnimation ra = new RotateAnimation (0,720, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
Anim. addAnimation ();
Anim. addAnimation (ra );
Anim. setDuration (3000 );
Anim. setStartOffset (1000 );
Iv. startAnimation (anim );
You can define multiple animations in the xml file so that multiple animations can be run together.
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator"
Android: Required interpolator = "true"
>
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: startOffset = "500"
Android: duration= "3000"
/>
<Rotate
Android: fromDegrees = "0"
Android: toDegrees = "400"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: duration= "3000"
/>
</Set>
<? Xml version = "1.0" encoding = "UTF-8"?>
<Set xmlns: android = "http://schemas.android.com/apk/res/android"
Android: interpolator = "@ android: anim/accelerate_interpolator"
Android: Required interpolator = "true"
>
<Alpha
Android: fromalphi = "1.0"
Android: toAlpha = "0.0"
Android: startOffset = "500"
Android: duration= "3000"
/>
<Rotate
Android: fromDegrees = "0"
Android: toDegrees = "400"
Android: Required Tx = "50%"
Android: Ty = "50%"
Android: duration= "3000"
/>
</Set>
Interpolator can define the animation playback speed
Define Interpolator in the xml file
Android: interpolator = "@ android: anim/accelerate_interpolator"
Android: Required interpolator = "true"
In this way, all animations share an Interpolator.
Set the following in the Code:
Anim. setInterpolator (new AccelerateInterpolator ());
If true is input in the new AnimationSet, all animations share Interpolator.