Drawable animation可以加载Drawable资源实现帧动画。AnimationDrawable是实现Drawable animations的基本类。推荐用XML文件的方法实现Drawable动画,不推荐在代码中实现。这种XML文件存放在工程中res/drawable/目录下。XML文件的指令(即属性)为动画播放的顺序和时间间隔。
在XML文件中
1 | <animation-list xmlns:android="http://schemas.android.com/apk/res/android" |
设置Android:oneshot属性为true,表示此次动画只执行一次,最后停留在最后一帧。设置为false则动画循环播放。文件可以添加为Image背景,触发的时候播放。
下面简单通过一个例子,来给ImageView设置次动画效果,具体实现方法为
通过View. setBackgroundResource(resID). animation.start().
1 | private AnimationDrawable animationDrawable; |
Demo地址:https://github.com/zhangmiaocc/AnimationDrawable
Blog地址:https://zhangmiao.cc/