There are two ways you can do animation in Android. The first is to set an animation for an ImageView object. That is, you apply basic motions, such as, rotation, shifting, etc to the bitmap inside the ImageView. Below is an example of the method:
private ImageView iv;
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
private ImageView iv;
iv = new ImageView(context);
iv.setImageResource(resourceIdOfImage);
RotateAnimation anim = new RotateAnimation(0.0f, 360.0f , Animation.RELATIVE_TO_SELF, .5f, Animation.RELATIVE_TO_SELF, .5f);
anim.setInterpolator(new LinearInterpolator());
anim.setRepeatCount(Animation.INFINITE);
anim.setDuration(3000);
iv.setAnimation(anim);
iv.startAnimation(anim);
Another way to create an animation is to animate a set of images. We need to create a list of images involved in animation:
customprogressdialog_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/anim1" android:duration="200" />
<item android:drawable="@drawable/anim2" android:duration="200" />
<item android:drawable="@drawable/anim3" android:duration="200" />
<item android:drawable="@drawable/anim4" android:duration="200" />
<item android:drawable="@drawable/anim5" android:duration="200" />
<item android:drawable="@drawable/anim6" android:duration="200" />
<item android:drawable="@drawable/anim7" android:duration="200" />
<item android:drawable="@drawable/anim8" android:duration="200" />
<item android:drawable="@drawable/anim9" android:duration="200" />
<item android:drawable="@drawable/anim10" android:duration="200" />
<item android:drawable="@drawable/anim11" android:duration="200" />
<item android:drawable="@drawable/anim12" android:duration="200" />
<item android:drawable="@drawable/anim13" android:duration="200" />
<item android:drawable="@drawable/anim14" android:duration="200" />
<item android:drawable="@drawable/anim15" android:duration="200" />
<item android:drawable="@drawable/anim16" android:duration="200" />
<item android:drawable="@drawable/anim17" android:duration="200" />
<item android:drawable="@drawable/anim18" android:duration="200" />
<item android:drawable="@drawable/anim19" android:duration="200" />
<item android:drawable="@drawable/anim20" android:duration="200" />
<item android:drawable="@drawable/anim21" android:duration="200" />
<item android:drawable="@drawable/anim22" android:duration="200" />
<item android:drawable="@drawable/anim23" android:duration="200" />
<item android:drawable="@drawable/anim24" android:duration="200" />
<item android:drawable="@drawable/anim25" android:duration="200" />
<item android:drawable="@drawable/anim26" android:duration="200" />
<item android:drawable="@drawable/anim27" android:duration="200" />
<item android:drawable="@drawable/anim28" android:duration="200" />
</animation-list>
And expose the list inside of the ImageView:
<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/pd_description"
android:scale
android:adjustViewBounds="true"/>
ImageView la = (ImageView) findViewById(R.id.animation);
la.setBackgroundResource(R.drawable.customprogressdialog_animation);
animation = (AnimationDrawable) la.getBackground();
customprogressdialog_animation.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list
xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="@drawable/anim1" android:duration="200" />
<item android:drawable="@drawable/anim2" android:duration="200" />
<item android:drawable="@drawable/anim3" android:duration="200" />
<item android:drawable="@drawable/anim4" android:duration="200" />
<item android:drawable="@drawable/anim5" android:duration="200" />
<item android:drawable="@drawable/anim6" android:duration="200" />
<item android:drawable="@drawable/anim7" android:duration="200" />
<item android:drawable="@drawable/anim8" android:duration="200" />
<item android:drawable="@drawable/anim9" android:duration="200" />
<item android:drawable="@drawable/anim10" android:duration="200" />
<item android:drawable="@drawable/anim11" android:duration="200" />
<item android:drawable="@drawable/anim12" android:duration="200" />
<item android:drawable="@drawable/anim13" android:duration="200" />
<item android:drawable="@drawable/anim14" android:duration="200" />
<item android:drawable="@drawable/anim15" android:duration="200" />
<item android:drawable="@drawable/anim16" android:duration="200" />
<item android:drawable="@drawable/anim17" android:duration="200" />
<item android:drawable="@drawable/anim18" android:duration="200" />
<item android:drawable="@drawable/anim19" android:duration="200" />
<item android:drawable="@drawable/anim20" android:duration="200" />
<item android:drawable="@drawable/anim21" android:duration="200" />
<item android:drawable="@drawable/anim22" android:duration="200" />
<item android:drawable="@drawable/anim23" android:duration="200" />
<item android:drawable="@drawable/anim24" android:duration="200" />
<item android:drawable="@drawable/anim25" android:duration="200" />
<item android:drawable="@drawable/anim26" android:duration="200" />
<item android:drawable="@drawable/anim27" android:duration="200" />
<item android:drawable="@drawable/anim28" android:duration="200" />
</animation-list>
And expose the list inside of the ImageView:
<ImageView
android:id="@+id/animation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/pd_description"
android:scale
android:adjustViewBounds="true"/>
ImageView la = (ImageView) findViewById(R.id.animation);
la.setBackgroundResource(R.drawable.customprogressdialog_animation);
animation = (AnimationDrawable) la.getBackground();