帧动画animation-list
程序员文章站
2022-03-16 16:13:51
...
帧动画是顺序包房一组预先定义好的图片,使用比较简单。如下
xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@drawable/ic_sunny"
android:duration="500" />
<item
android:drawable="@drawable/ic_night"
android:duration="500" />
<item
android:drawable="@drawable/ic_cloudy"
android:duration="500" />
</animation-list>
布局
<ImageView
android:id="@+id/iv_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bg_animation_list" />
代码实现
iv_image.setImageResource(R.drawable.bg_animation_list)
var d: AnimationDrawable =
iv_image.drawable as AnimationDrawable
d.start()
iv_image.setOnClickListener {
if (d.isRunning) {
d.stop()
} else {
d.start()
}
}
效果