Android: Animate Circular Progress Drawable
I need a drawable that looks like the rotating progress circle. That drawable I want to use for instance in an ImageView inside a GridView etc. So, according to other posts I took
Solution 1:
There is a View
named ProgressBar
that does exactly what you want.
Just use this instead of your ImageView
:
<ProgressBar
android:id="@+id/element_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingBottom="5dp"
android:paddingTop="5dp" />
Solution 2:
In order to create a customized progress indicator (rotating progress circle, in your case)
- Create a layout file(.xml) or use an image (drawable) for roatating circle. Put it in drawable folder in res.
- Use this drawable as a source to the imageview in the layout for loading indicator.
- Use this imageview by inflating and call following startLoadingAnimation() on it.Similarly you can stop the animation once your job is done by simply calling stopLoadingAnimation() on it.
You will have to use animation to make it rotate.
// start the loading animationpublicvoidstartLoadingAnimation(Context context) {
Animation rotate = AnimationUtils.loadAnimation(context,
R.anim.anim_rotate);
rotate.setRepeatMode(Animation.INFINITE);
mImgView.startAnimation(rotate);
}
// stop the loading animationpublicvoidstopLoadingAnimation(){
mImgView.clearAnimation();
}
anim_rotate.xml
put this file in anim
folder in res
<?xml version="1.0" encoding="utf-8"?><rotatexmlns: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="500"android:startOffset="0"android:repeatCount="infinite"
/>
Solution 3:
Thanks for progress_medium_holo.xml. In my case a standard ProgressBar (for API 23) was not visible, I tryed many variations, only horizontal bar styled progressbars were visible. Then I copied progress_medium_holo.xml and linked drawables from the folder sdk\platforms\android-xx\data\res\drawable and eventually got:
<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateDrawable="@drawable/progress_medium_holo"/>
Post a Comment for "Android: Animate Circular Progress Drawable"