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:
- EXAMPLE:
-
-
XML file saved at
-
<?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()
;
res/anim/rocket.xml
:
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 吧