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()
}

猜你喜欢

转载自blog.csdn.net/qq_36968707/article/details/82114586