android 动画资源Frame动画

Frame动画

按照指定的图片顺序播放动画。

xml文件位置:res/drawable/filename.xml

对应类:AnimationDrawable

资源引用:In Java: R.drawable.filename In XML: @[package:]drawable.filename 

 

xml定义语法:

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

<animation-list>:根元素,包含其他item

android:oneshot  是否只播放一次,false 循环播放

<item>:单个动画

android:drawable 播放图片

android:duration   Integer. 播放时间(毫秒)

demo:

rocket.xml

<?xml version="1.0" encoding="utf-8"?>
<animation-listxmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <itemandroid:drawable="@drawable/rocket_thrust1"android:duration="200"/>
    <itemandroid:drawable="@drawable/rocket_thrust2"android:duration="200"/>
    <itemandroid:drawable="@drawable/rocket_thrust3"android:duration="200"/>
</animation-list>

ImageView rocketImage =(ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

rocketAnimation =(AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();

 

猜你喜欢

转载自xxmy.iteye.com/blog/1982859