Issue
I have two rotate drawables inside a layer-list
and I'm trying to animate them both as a drawableleft
on a button. I'm getting the drawables displayed but no animation.
This is my drawable layout in xml (button_progress_bar_small.xml
) :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<rotate
android:drawable="@drawable/ic_spinner_small_outer"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="1080" />
</item>
<item>
<rotate
android:drawable="@drawable/ic_spinner_small_inner"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="720"
android:toDegrees="0" />
</item>
And this is the code I'm running :
button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.button_progress_bar_small, 0, 0, 0);
LayerDrawable progressAnimationLeft = (LayerDrawable) button.getCompoundDrawables()[0];
((RotateDrawable) progressAnimationLeft.getDrawable(0)).setLevel(500);
((RotateDrawable) progressAnimationLeft.getDrawable(1)).setLevel(500);
I'm not really sure what is the trigger for the animation to start or whether i should execute something on each RotateDrawable
(in contrary to a one action on LayerDrawable
) in order to do that.
Solution
ok, i found a solution for my problem.
i changed the layout to :
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_spinner_small_outer"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="0"
android:toDegrees="1080"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"/>
</item>
<item>
<animated-rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_spinner_small_inner"
android:pivotX="50%"
android:pivotY="50%"
android:fromDegrees="720"
android:toDegrees="0"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"/>
</item>
and changed the code to :
button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.button_progress_bar_small, 0, 0, 0);
LayerDrawable progressAnimationLeft = (LayerDrawable) button.getCompoundDrawables()[0];
((Animatable) progressAnimationLeft.getDrawable(0)).start();
((Animatable) progressAnimationLeft.getDrawable(1)).start();
its not really answering the question but its a good workaround for me with the same animation affect.
Answered By - AsafK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.