I could not find how to change the animator in the ProgressBar
, so I suggest you go with your own drawable.
Draw progress as a rectangle
In a trivial example, let progress look like a rectangle:
res/drawable/vector_drawable_progress_indeterminate_horizontal.xml
(name inspired by core / res / res / drawable / vector_drawable_progress_indeterminate_horizontal.xml )
<?xml version="1.0" encoding="utf-8"?> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="10dp" android:width="100dp" android:viewportHeight="10" android:viewportWidth="100" > <group android:name="rect1_grp" android:scaleX="1" > <path android:pathData="M 0,0 h 100 v 10 h -100 Z" android:fillColor="?attr/colorControlActivated" /> </group> </vector>
Animate horizontal scale
Of course, this rectangle is not animated at all, so you want to wrap it in an object that changes its horizontal scale ( scaleX
of rect1_grp
).
res/drawable/custom_progress.xml
<?xml version="1.0" encoding="utf-8"?> <animated-vector android:drawable="@drawable/vector_drawable_progress_indeterminate_horizontal" xmlns:android="http://schemas.android.com/apk/res/android"> <target android:animation="@anim/progress_indeterminate_horizontal_rect1" android:name="rect1_grp"/> </animated-vector>
The only thing left to do is create your own animation:
res/anim/progress_indeterminate_horizontal_rect1
:
<set xmlns:android="http://schemas.android.com/apk/res/android"> <objectAnimator android:duration="1500" android:propertyName="scaleX" android:valueFrom="0" android:valueTo="1" android:valueType="floatType" android:repeatMode="reverse" android:repeatCount="infinite"/> </set>
The animation grows linearly from 0f to 1f and repeats endlessly with the reverse mode (which avoids the sequence of two animators: one for zooming in and one for zooming out).
Enjoy
Now all you have to do is use it in res/layout/activity.xml
:
<ProgressBar xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="8dip" android:indeterminate="true" android:indeterminateDrawable="@drawable/custom_progress" />
Left to do
- I divided the progress to a minimum. You might want to get a wallpaper. You can also restore secondary progress.
- You can adjust the interpolator in the animation.