res-----不同圖片實現動畫效果(幀動畫)
1、準備幾張圖片(可命名為a1-a6)
2、在drawable資料夾下新建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="@drawable/a1"
android:duration="50">
</item>
<item
android:drawable="@drawable/a2"
android:duration="50">
</item>
<item
android:drawable="@drawable/a3"
android:duration="50">
</item>
<item
android:drawable="@drawable/a4"
android:duration="50">
</item>
<item
android:drawable="@drawable/a5"
android:duration="50">
</item>
<item
android:drawable="@drawable/a6"
android:duration="50">
</item>
</animation-list>
3、引用(可以寫一個工具類)
/**
* 幀動畫
*/
fun drawableAnim(imageView: ImageView, drawableId: Int) {
imageView.setBackgroundResource(drawableId)
val mAnimationDrawable = imageView.getBackground() as AnimationDrawable
mAnimationDrawable.start()
}