Android provides 4 Animation:
AlphaAnimation transparency animation effect
ScaleAnimation scaling animation effect
TranslateAnimation displacement animation effect
RotateAnimation rotation animation effect
This section describes the ScaleAnimation animation,
ScaleAnimation (float fromX, float toX, float fromY, float toY, int limit txtype, float limit txvalue, int limit tytype, float limit tyvalue)
Parameter description:Copy codeThe Code is as follows: the scaling size on the X coordinate at the start of the float fromX Animation
Scaling size on the X coordinate when float toX animation ends
Scaling size on Y coordinate at the start of float fromY Animation
Scaling size on Y coordinate when float toY animation ends
The type of the int extension txtype animation position on the X axis relative to the object
The starting position of the float pivotXValue animation relative to the X coordinate of the object
The type of the int tytytype animation position relative to the object on the Y axis.
The starting position of the float tyvalue animation relative to the Y coordinate of the object
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 scaling animation */
Final ScaleAnimation animation = new ScaleAnimation (0.0f, 1.4f, 0.0f, 1.4f,
Animation. RELATIVE_TO_SELF, 0.5f, Animation. RELATIVE_TO_SELF, 0.5f );
Animation. setDuration (2000); // 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: