Simple Rotate Animation in ANdroid using XML

It is very common that you have seen some simple animations in most of the applications in Android. Animations can give better user experience for your applications. In this example, I’ll try to introduce you doing simple animations with Android. It is simple enough that on clicking a button, an images starts rotating from 0 degree to 360 degree in N seconds. Lets begin with the animation XML. Once you have created a new Android project, create a folder named anim in res and a file named rotator.xml inside res/anim.


Hope the code is pretty self explanatory. Here one complete rotation will be completed in 4000ms (4 seconds). Now add a PNG image that you want to rotate into your drawable folder. Then open res/main.xml, after removing the default textView in the layout, add an ImageView and Button into the layout. Set the src property of the ImageView as your filename of the added image, for example android:src=”@drawable/myimg” Ok, lets edit the main class. In the onClick() for the button, add the necessary code for running the animation. Check the following code.
public class AnimationActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        ((Button)findViewById( OnClickListener()    {
            public void onClick(View arg0) {
                final ImageView myImage = (ImageView)findViewById(;
                final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator);

Blazin Battery Saver

Blazin battery saver Application launched recently which is a battery optimisation tool having sleek look and feel and making plenty of downloads on the google play

have a look on it ,.

Post a Comment