The best way to animate images in Android is to use the AnimationDrawable system. To do this, you need an xml similar to the one below in one of your drop-down folders.
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true"> <item android:drawable="@drawable/image1" android:duration="200" /> <item android:drawable="@drawable/image2" android:duration="200" /> <item android:drawable="@drawable/image3" android:duration="200" /> </animation-list>
If image1, image2 and image3 are different resources in your resources, each of which represents a different state of your image.
To create images, you can simply open your image using Gimp or Photoshop and rotate it several degrees and export to a new image and repeat.
Alternatively, you can use the following code to rotate the ImageView. First create the โanimโ folder in the res folder and add the rotate.xml file with the following contents:
<rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:interpolator="@android:anim/linear_interpolator" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:duration="1000" android:startOffset="0" />
then import and run the animation as follows:
Animation rotation = AnimationUtils.loadAnimation(this, R.anim.rotation); rotation.setRepeatCount(Animation.INFINITE); imageView.startAnimation(rotation);
source share