android 给逐帧动画AnimationDrawable 设置定时器
程序员文章站
2022-03-02 08:17:29
...
比如,逐帧动画我只想让他播放10秒,10秒后自动停止
动画文件anim_voice_paly.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<item
android:drawable="@mipmap/receiver_voice_node_playing003"
android:duration="200" />
<item
android:drawable="@mipmap/receiver_voice_node_playing002"
android:duration="200" />
<item
android:drawable="@mipmap/receiver_voice_node_playing001"
android:duration="200" />
</animation-list>
布局xml
<ImageView
android:id="@+id/img_voice"
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_centerVertical="true"
android:src="@drawable/anim_voice_paly" />
Activity代码
ImageView img_voice.setImageResource(R.drawable.anim_voice_paly);
AnimationDrawable voice_paly_drawable = (AnimationDrawable)img_voice.getDrawable();
voice_paly_drawable.start();
VerificationCountDownTimer verificationCountDownTimer = new VerificationCountDownTimer(10 * 1000, 1000) {
@Override
public void onTick(long millisUntilFinished) {
//每隔1秒调用,可以直接操作UI
}
/**
* 当前任务完成的时候回调
*/
@Override
public void onFinish() {
//停止动画
voice_paly_drawable.stop();
//设置回一开始的样子
img_voice.setImageResource(R.drawable.anim_voice_paly);
}
};
verificationCountDownTimer.start();
上一篇: Lua学习笔记之数据结构
下一篇: A-frame中component的理解