4 animations are available in Android:
Alphaanimation Transparency Animation effect
Scaleanimation Zoom Animation effect
Translateanimation Displacement Animation effect
Rotateanimation Rotate animation effect
This section explains Rotateanimation animations,
Rotateanimation (float fromdegrees, float todegrees, int pivotxtype, float pivotxvalue, int pivotytype, float pivotyvalue)
Parameter description:
Float fromdegrees: The start angle of the rotation.
Float todegrees: The end angle of the rotation.
int pivotxtype:x The scaling mode of the axis, you can take the value of absolute, relative_to_self, relative_to_parent.
The scaling value of the float pivotxvalue:x coordinates.
int Pivotytype:y The scaling mode of the axis, you can take the value of absolute, relative_to_self, relative_to_parent.
The scaling value of the float pivotyvalue: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 Rotation animation */
Final rotateanimation animation =new rotateanimation (0f,360f,animation.relative_to_self,
0.5f,animation.relative_to_self,0.5f);
Animation.setduration (3000);//Set animation duration
/** Common Methods */
Animation.setrepeatcount (int repeatcount);//Set the number of repetitions
Animation.setfillafter (Boolean);//Whether the animation stays in the finished state after execution
Animation.setstartoffset (long Startoffset);//wait 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:
Android Animation's rotateanimation application detailed