4 animations are available in Android:
Alphaanimation Transparency Animation effect
Scaleanimation Zoom Animation effect
Translateanimation Displacement Animation effect
Rotateanimation Rotation animation effect
This section explains Scaleanimation animations,
Scaleanimation (float FromX, float toX, float fromY, float toy,int pivotxtype, float pivotxvalue, int pivotytype, float PIV Otyvalue)
Parameter description:
Copy Code code as follows:
Float FromX the size of the expansion on the X coordinate at the start of the animation
Expansion dimensions on x coordinates at the end of float ToX animation
Float FromY The expansion dimension on the y-coordinate at the start of the animation
Expansion dimensions on y-coordinates at the end of float ToY animation
int Pivotxtype animation on X axis relative to object position type
The start position of the float Pivotxvalue animation relative to the x-coordinate of the object
int Pivotytype animation on Y axis relative to object position type
Float Pivotyvalue The starting position of the animation relative to the y-coordinate of the object
Code:
Copy Code code 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 Zoom 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);//Set animation duration
/** Common Method * *
Animation.setrepeatcount (int repeatcount);//Set Number of repetitions
Animation.setfillafter (Boolean)//whether the animation is finished after the execution of the state
Animation.setstartoffset (long Startoffset)//wait time before execution
Start.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
Image.setanimation (animation);
/** Start the animation *
Animation.startnow ();
}
});
Cancel.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
/** End Animation *
Animation.cancel ();
}
});
}
}
Effect: