Rotate drawable , proposed by Praveen, will not give you control over the number of frames. Suppose you want to implement a custom loader consisting of 8 sections:

Using the animation-list approach, you need to create 8 frames rotated 45*frameNumber degrees manually. In addition, you can use the 1st frame and set the rotation animation for it:

File res/anim/progress_anim.xml :
<?xml version="1.0" encoding="utf-8"?> <rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="360" android:pivotX="50%" android:pivotY="50%" android:repeatCount="infinite" />
MainActivity.java File
Animation a = AnimationUtils.loadAnimation(getContext(), R.anim.progress_anim); a.setDuration(1000); imageView.startAnimation(a);
This will give you smooth animation instead of an 8-speed one. To fix this, we need to implement a custom interpolator:
a.setInterpolator(new Interpolator() { private final int frameCount = 8; @Override public float getInterpolation(float input) { return (float)Math.floor(input*frameCount)/frameCount; } });
You can also create your own widget:
File res/values/attrs.xml :
<?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="ProgressView"> <attr name="frameCount" format="integer"/> <attr name="duration" format="integer" /> </declare-styleable> </resources>
File ProgressView.java :
public class ProgressView extends ImageView { public ProgressView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setAnimation(attrs); } public ProgressView(Context context, AttributeSet attrs) { super(context, attrs); setAnimation(attrs); } public ProgressView(Context context) { super(context); } private void setAnimation(AttributeSet attrs) { TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.ProgressView); int frameCount = a.getInt(R.styleable.ProgressView_frameCount, 12); int duration = a.getInt(R.styleable.ProgressView_duration, 1000); a.recycle(); setAnimation(frameCount, duration); } public void setAnimation(final int frameCount, final int duration) { Animation a = AnimationUtils.loadAnimation(getContext(), R.anim.progress_anim); a.setDuration(duration); a.setInterpolator(new Interpolator() { @Override public float getInterpolation(float input) { return (float)Math.floor(input*frameCount)/frameCount; } }); startAnimation(a); } }
Activity_main.xml file:
<com.example.widget.ProgressView android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/ic_progress" app:frameCount="8" app:duration="1000"/>
res/anim/progress_anim.xml file: listed above