点击ImageView
时,我正在尝试使用AnimationDrawable显示一个帧来制作动画。但是当我点击ImageView
时,我的动画只发生一次。我正在使用xml作为动画。
动画xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="true">
<item android:drawable="@drawable/scorepopup1" android:duration="100" />
<item android:drawable="@drawable/scorepopup2" android:duration="100" />
<item android:drawable="@drawable/scorepopup3" android:duration="100" />
<item android:drawable="@drawable/scorepopup4" android:duration="100" />
<item android:drawable="@drawable/invipopup" android:duration="100" />
</animation-list>
这是我的按钮xml和动画图像的容器:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="70dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_margin="5dp">
<ImageView
android:layout_width="35dp"
android:layout_height="35dp"
android:background="@drawable/bd"
android:layout_margin="10dp"
android:onClick="checkGem"
android:contentDescription="bd"/>
<ImageView
android:id="@+id/scorePopup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp" />
</LinearLayout>
checkGem方法:
ImageView popup1 = (ImageView) findViewById(R.id.scorePopup);
popup1.setBackgroundResource(R.drawable.popup1_animation);
AnimationDrawable frameAnimation2 = (AnimationDrawable)
popup1.getBackground();
frameAnimation2.start();
我的问题是动画只显示一次,但我希望每次点击都能动画。有什么想法吗?
答案 0 :(得分:4)
在stop()
电话前ImageView
的{{1}}背景上发出AnimationDrawable
来电:
start()
当您第一次单击//...
AnimationDrawable frameAnimation2 = (AnimationDrawable) popup1.getBackground();
frameAnimation2.stop();
frameAnimation2.start();
动画将运行时,但最后它将发现自己处于认为仍在运行的状态。在那种状态下,调用ImageView
将被忽略。 start()
方法“重置”该状态,stop()
将从头开始运行。