Android 官网 Animation Resources 的一个bug?

本文详细介绍了如何使用XML定义Frame动画,并通过Java代码实现背景设置与播放。包括动画列表元素、帧元素属性和一个具体示例。此外,文章还讨论了与资源引用的相关问题。

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

http://developer.android.com/guide/topics/resources/animation-resource.html#Frame

Frame animation

An animation defined in XML that shows a sequence of images in order (like a film).

FILE LOCATION:
res/drawable/filename.xml
The filename will be used as the resource ID.
COMPILED RESOURCE DATATYPE:
Resource pointer to an  AnimationDrawable.
RESOURCE REFERENCE:
In Java:  R.drawable.filename
In XML:  @[package:]drawable.filename
SYNTAX:
<?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>
ELEMENTS:
<animation-list>
Required. This must be the root element. Contains one or more  <item> elements.

attributes:

android:oneshot
Boolean. "true" if you want to perform the animation once; "false" to loop the animation.
<item>
A single frame of animation. Must be a child of a  <animation-list> element.

attributes:

android:drawable
Drawable resource. The drawable to use for this frame.
android:duration
Integer. The duration to show this frame, in milliseconds.
EXAMPLE:
XML file saved at  res/anim/rocket.xml:
<?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/rocket_thrust1" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust2" android:duration="200" />
    <item android:drawable="@drawable/rocket_thrust3" android:duration="200" />
</animation-list>
This application code will set the animation as the background for a View, then play the animation:
ImageView rocketImage = (ImageView) findViewById(R.id.rocket_image);
rocketImage.setBackgroundResource(R.drawable.rocket_thrust);

rocketAnimation = (AnimationDrawable) rocketImage.getBackground();
rocketAnimation.start();
SEE ALSO:

问题如下:

XML file saved at res/anim/rocket.xml:

文件为  R.anim.rocket

但是 Example 里头 调用的 为 R.drawable.rocket_thrust

虽然  drawable里头添加了 rocket_thrust1, rocket_thrust2, rocket_thrust3

此为bug 吧  



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值