如何重播一次性动画

sli*_*ull 6 android android-animation

我想制作一个动画,但能够按照我想要的次数播放它.现在它只是第一次播放.

.XML:

<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/p1_ch1" android:oneshot="true">
    <item 
      android:drawable="@drawable/p1_ch1_5" 
      android:duration="500"/>
    <item 
      android:drawable="@drawable/p1_ch1_4" 
      android:duration="1000"/>
    <item 
      android:drawable="@drawable/p1_ch1_5" 
      android:duration="500"/>
</animation-list>
Run Code Online (Sandbox Code Playgroud)

的.java:

public void handler_p1_ch1_5 (View target){
      ImageView iv = (ImageView)findViewById(R.id.p1_ch1_5);
      AnimationDrawable aw = (AnimationDrawable)iv.getBackground();
      aw.start();
}
Run Code Online (Sandbox Code Playgroud)

sli*_*ull 15

只需在aw.start()之前调用aw.stop()