Frame动画
文件目录:res/drawable/filename.xml
编译资源数据类型 AnimationDrawable
资源引用:
Java: R.drawable.filename
XML: @[package:]drawable.filename
1 2 3 4 5 6 7 | <?xml version="1.0" encoding="utf-8"?> <animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot=["true" | "false"] > <item android:drawable="@[package:]drawable/drawable_resource_name" android:duration="integer" /> </animation-list> |
必须作为根元素,包含一个或者多个根元素
属性:android:oneshot :true:只执行一次动画,false:循环执行
A single frame of animation. Must be a child of a element.
一帧独立动画,必须是的子元素。
属性
android:drawable
Drawable资源,用于这一帧的图片。
android:duration
Integer类型.该帧的时长,单位为毫秒milliseconds.
res/drawable/voice.xml: 这个动画就是每200毫秒循环显示图片,fasong1,fasong2,fasong3 如果oneshot 为true 则只执行一次
1 2 3 4 5 6 7 | <?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/fasong1" android:duration="200" /> <item android:drawable="@drawable/fasong2" android:duration="200" /> <item android:drawable="@drawable/fasong3" android:duration="200" /> </animation-list> |
调用代码:
// 帧动画启动
animationDrawable = (AnimationDrawable) imageView.getBackground();
animationDrawable.start();
// 帧动画停止
animationDrawable.stop();