Yes! The key (undocumented) that I discovered while reading the ProgressBar code is that you have to call Drawable.setLevel() in onDraw() so that the <rotate> object has any effect. ProgressBar works something like this (superfluous non-essential code is omitted):
Selectable XML:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <rotate android:drawable="@drawable/spinner_48_outer_holo" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="0" android:toDegrees="1080" /> </item> <item> <rotate android:drawable="@drawable/spinner_48_inner_holo" android:pivotX="50%" android:pivotY="50%" android:fromDegrees="720" android:toDegrees="0" /> </item> </layer-list>
In onDraw() :
Drawable d = getDrawable(); if (d != null) {
MAX_LEVEL is a constant and always 10000 (according to the docs). ANIM_PERIOD is the period of your animation in milliseconds.
Unfortunately, since you need to change onDraw() , you cannot just put this drawable into an ImageView , since ImageView never changes the allowable level. However, you can change the output level from outside the ImageView . ProgressBar (ab) uses AlphaAnimation to set the level. So you would do something like this:
mMyImageView.setImageDrawable(myDrawable); ObjectAnimator anim = ObjectAnimator.ofInt(myDrawable, "level", 0, MAX_LEVEL); anim.setRepeatCount(ObjectAnimator.INFINITE); anim.start();
This might work, but I have not tested it.
Edit
In fact, there is an ImageView.setImageLevel() method, so it can be as simple as:
ObjectAnimator anim = ObjectAnimator.ofInt(myImageVew, "ImageLevel", 0, MAX_LEVEL); anim.setRepeatCount(ObjectAnimator.INFINITE); anim.start();
Timmmm
source share