我需要将此动画显示为按钮背景

ste*_*ven 2 java android image button

如果有人可以提供帮助,我会非常感激.基本上我想要获得这个动画GIF或其他需要的东西,以显示为按钮背景.当我单击按钮时,我希望它更改为显示旋转器旋转的动画.知道如何让这个动画GIF作为一个可绘制的按钮背景工作吗?

小智 5

我就是这样做的.首先拆分GIF并将每个图像添加到drawable文件夹中.然后将新的xml文件添加到drawable(animation.xml)....请参阅下面的示例

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
 android:oneshot="false">
<item android:drawable="@drawable/santa1" android:duration="200" />
<item android:drawable="@drawable/santa2" android:duration="200" />
<item android:drawable="@drawable/santa3" android:duration="200" />
<item android:drawable="@drawable/santa4" android:duration="200" />
<item android:drawable="@drawable/santa5" android:duration="200" />
<item android:drawable="@drawable/santa6" android:duration="200" />
<item android:drawable="@drawable/santa7" android:duration="200" />

</animation-list>
Run Code Online (Sandbox Code Playgroud)

然后当你想要它开始用下面的例子来调用它....

b_1.setBackgroundResource(R.drawable.animation);
                         AnimationDrawable b1Amin = (AnimationDrawable) b_1.getBackground();
                        b1Amin.start();
Run Code Online (Sandbox Code Playgroud)