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.

android:duration="”4000”" 
android:fromdegrees="”0”" 
android:pivotx="”50%”" 
android:pivoty="”50%”"
android:todegrees="”360”" 
android:toyscale="”0.0”" 

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 {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        ((Button)findViewById(R.id.button1)).setOnClickListener(new OnClickListener()    {
            @Override
            public void onClick(View arg0) {
                final ImageView myImage = (ImageView)findViewById(R.id.imageView1);
                final Animation myRotation = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.rotator);
                myImage.startAnimation(myRotation);
            }
        });
    }
}



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


https://play.google.com/store/apps/details?id=com.shir60bhushan.blazinbattery&hl=en

have a look on it ,.


Post a Comment