gpt4 book ai didi

android - 在 LayerDrawable 中对所有 RotateDrawables 进行动画处理

转载 作者:太空狗 更新时间:2023-10-29 12:46:18 24 4
gpt4 key购买 nike

我在 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 上的一个 Action 相反) 为了做到这一点。

最佳答案

好的,我找到了解决问题的方法。

我将布局更改为:

<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();

它并没有真正回答问题,但它对我来说是一个很好的解决方法,具有相同的动画效果。

关于android - 在 LayerDrawable 中对所有 RotateDrawables 进行动画处理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17854684/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com