Android Tweened Animation has four types
Alpha: fade in and fade out
Scale: Scaling Effect
Rotate: rotation effect
Translate: Moving Effect
Procedure for using Tweened Animations
1. Create an AnimationSet object
2. Create the expected Animation object as needed
3. Set the corresponding data for the Animation object based on the needs of the software Animation.
4. Add the Animation object to the AnimationSet object.
5. Make the control object start executing the AnimationSet
Alpha Animation
[Java]
AnimationSet as = new AnimationSet (true );
AlphaAnimation al = new AlphaAnimation (1, 0 );
// 1 indicates completely opaque, and 0 indicates completely transparent
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
AnimationSet as = new AnimationSet (true );
AlphaAnimation al = new AlphaAnimation (1, 0 );
// 1 indicates completely opaque, and 0 indicates completely transparent
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation (as); Rotate Animation
[Java]
AnimationSet as = new AnimationSet (true );
RotateAnimation al = new RotateAnimation (0,720, Animation. RELATIVE_TO_PARENT, 0.5f, Animation. RELATIVE_TO_PARENT, 0.5f );
// The Rotation Angle of the first two parameters. The following parameters determine the rotation center.
// Animation. ABSOLUTE: ABSOLUTE Coordinate
// Animation. RELATIVE_TO_PARENT: relative to the parent Control
// Animation. RELATIVE_TO_SELF: relative to yourself
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
AnimationSet as = new AnimationSet (true );
RotateAnimation al = new RotateAnimation (0,720, Animation. RELATIVE_TO_PARENT, 0.5f, Animation. RELATIVE_TO_PARENT, 0.5f );
// The Rotation Angle of the first two parameters. The following parameters determine the rotation center.
// Animation. ABSOLUTE: ABSOLUTE Coordinate
// Animation. RELATIVE_TO_PARENT: relative to the parent Control
// Animation. RELATIVE_TO_SELF: relative to yourself
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation (as); Scale Animation
[Java]
AnimationSet as = new AnimationSet (true );
ScaleAnimation al = new ScaleAnimation (, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
// The first four parameters are the size from X to Y, and the size from Y. The following parameters are the center point of scaling.
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
AnimationSet as = new AnimationSet (true );
ScaleAnimation al = new ScaleAnimation (, Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
// The first four parameters are the size from X to Y, and the size from Y. The following parameters are the center point of scaling.
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
Translate Animation
[Java]
AnimationSet as = new AnimationSet (true );
TranslateAnimation al = new TranslateAnimation (Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 2, Animation. Parent, 0, Animation. RELATIVE_TO_SELF, 2 );
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
AnimationSet as = new AnimationSet (true );
TranslateAnimation al = new TranslateAnimation (Animation. RELATIVE_TO_SELF, 0, Animation. RELATIVE_TO_SELF, 2, Animation. Parent, 0, Animation. RELATIVE_TO_SELF, 2 );
Al. setDuration (3000 );
As. addAnimation (al );
Iv. startAnimation ();
There are several ways to use Animation
SetFillAfter (boolean fillAfter)
If the fillAfter value is true, after the animation ends, the control stays in the status after execution.
SetFillBefore (boolean fillBefore)
If the fillBefore value is true, after the animation ends, the control stays in the starting state of the animation.
SetStartOffset (long startOffset)
Set the waiting time before the animation is executed by the animation control.
SetRepeatCount (int repeatCount)
Set the number of repeated animation executions