Loading...

Android Rotate Animation Example

In android, animation can be created from different ways using xml or java code. In this tutorial, I am going to show to create rotating animation using xml. To create animation using xml, first you have to create an xml file inside res/anim/ directory.

In this tutorial, I have used an image view and a button in xml layout file to rotate an image when button is clicked and you have to add little bit java code in your activity file.

Related:
Zoom In Animation in Android
Fade Out Animation in Android
How to Implement Ripple Effect in Android

Rotate Animation Example: How to Rotate an Image in Android using XML Animation


XML Layout File

res/layout/android_rotate_animation_example.xml

Now, create android_rotate_animation.xml file in res/anim/ directory and add the content given below.
res/anim/android_rotate_animation.xml

Java Activity File

res/RotateAnimationExample.java

Strings.xml File

res/values/strings.xml

Now, run your android rotate animation example application and click the Stat Rotating button.

Output:

Rotate Animation Example: How to Rotate an Image in Android using XML Animation
Fig 1: Android Rotate Animation Example

Rotate Animation Example: How to Rotate an Image in Android using XML Animation
Fig 2: Start Rotating Animation when Button is Clicked

XML 2091475301981125803
Home item