android – 如何重放一次性动画

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

.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>

的.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();
}

解决方法

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

相关文章

ADB Remote ATV Android TV 的遥控器,基于 ADB Shell 命令 ...
使用Flutter自带的SearchDelegate组件实现搜索界面,通过魔改...
上篇文章讲解了怎么使用Kotlin的协程配合Retrofit发起网络请...
安卓开发——WebView+Recyclerview文章详情页,解决高度...
Android 如何解决dialog弹出时无法捕捉Activity的back事件 在...