drawable 目錄下創建button_play_animation.xml 動畫
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/ques_play0" android:duration="100" />
<item android:drawable="@drawable/ques_play1" android:duration="100" />
<item android:drawable="@drawable/ques_play2" android:duration="100" />
<item android:drawable="@drawable/ques_play3" android:duration="100" />
</animation-list>
((ImageView) v).setImageResource(R.drawable.button_play_animation);
AnimationDrawable animationDrawable = (AnimationDrawable) ((ImageView) v).getDrawable();
然後在播放的監聽事件中添加
animationDrawable.start(); //開始的時候調用
animationDrawable.stop(); //動畫結束調用
在播放結束之後可以給ImageView設置drawable
((ImageView) v).setImageResource(R.drawable.ques_play3);