我在一个layer-list中有两个旋转的绘图,我试图将它们作为一个按钮上的drawableleft来动画。我得到的绘图显示,但没有动画。
这是我在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>
这是我正在运行的代码:
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);我不太确定动画启动的触发器是什么,也不确定是否应该在每个RotateDrawable上执行某些操作(与LayerDrawable上的一个操作相反)。
发布于 2013-07-25 19:10:34
好吧,我找到了解决问题的办法。
我将布局更改为:
<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>
并将代码更改为:
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();这不是真正的回答问题,但它是一个很好的解决办法,我与相同的动画效果。
发布于 2015-06-17 20:40:08
您必须动画级别值,其范围从0到10000。
button.setCompoundDrawablesWithIntrinsicBounds(R.drawable.button_progress_bar_small, 0, 0, 0);
LayerDrawable progressAnimationLeft = (LayerDrawable) button.getCompoundDrawables()[0];
ObjectAnimator.ofInt((RotateDrawable) progressAnimationLeft.getDrawable(0), "level", 0, 10000).start();
ObjectAnimator.ofInt((RotateDrawable) progressAnimationLeft.getDrawable(1), "level", 0, 10000).start();https://stackoverflow.com/questions/17854684
复制相似问题