Android provides 4 Animation:
AlphaAnimation transparency animation effect
ScaleAnimation scaling animation effect
TranslateAnimation displacement animation effect
RotateAnimation rotation animation effect
This section describes the RotateAnimation animation,
RotateAnimation (float fromDegrees, float toDegrees, int limit txtype, float limit txvalue, int limit tytype, float limit tyvalue)
Parameter description:
Float fromDegrees: the starting angle of rotation.
Float toDegrees: the end angle of the rotation.
Int limit txtype: The scaling mode of the X axis. values include ABSOLUTE, RELATIVE_TO_SELF, and RELATIVE_TO_PARENT.
Float limit txvalue: The scaling value of X coordinates.
Int equaltytype: The scaling mode of the Y axis. values include ABSOLUTE, RELATIVE_TO_SELF, and RELATIVE_TO_PARENT.
Float tytyvalue: The scaling value of Y coordinates.
Code:Copy codeThe Code is as follows: public class MainActivity extends Activity {
ImageView image;
Button start;
Button cancel;
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. activity_main );
Image = (ImageView) findViewById (R. id. main_img );
Start = (Button) findViewById (R. id. main_start );
Cancel = (Button) findViewById (R. id. main_cancel );
/** Set the rotation animation */
Final RotateAnimation animation = new RotateAnimation (0f, 360f, Animation. RELATIVE_TO_SELF,
0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
Animation. setDuration (3000); // sets the animation duration.
/** Common methods */
// Animation. setRepeatCount (int repeatCount); // you can specify the number of repetitions.
// Animation. setFillAfter (boolean); // whether the animation is in the running state after execution
// Animation. setStartOffset (long startOffset); // the waiting time before execution
Start. setOnClickListener (new OnClickListener (){
Public void onClick (View arg0 ){
Image. setAnimation (animation );
/** Start animation */
Animation. startNow ();
}
});
Cancel. setOnClickListener (new OnClickListener (){
Public void onClick (View v ){
/** End animation */
Animation. cancel ();
}
});
}
}
Effect: