android 动画资源Frame动画

本文介绍如何使用Android中的Frame动画创建动态效果。通过定义XML文件设置动画列表,包括播放的图片序列及持续时间,并展示了如何在代码中启动动画。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值