帧动画animation-list

帧动画是顺序包房一组预先定义好的图片,使用比较简单。如下

xml


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

布局

    

代码实现

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

效果

你可能感兴趣的:(Android)