1. This type of animation can create a drawable sequence that can be displayed intermittently one at a specified time.
XML definition Methods
1 <animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"2 Android:oneshot= "false">3 <Itemandroid:drawable= "TU1"android:duration= "$"/>4 <Itemandroid:drawable= "TU2"android:duration= "$"/>5 <Itemandroid:drawable= "TU3"android:duration= "$"/>6 </animation-list>
2. Frames-per-frame animation is a picture created under drawable, the root node is animation-list (animated list), the OneShot property indicates whether it is played only once, and the animation is declared internally with the item node.
Where drawable indicates the use of the picture, the Duration property of this animation shows the time, in milliseconds.
You can then use it as a background image.
1 < TextView 2 Android:id = "@+id/main_tv" 3 android:layout_width= "100DP"4 android:layout_height= " 100DP "5 android:background=" @drawable/animation_list "/>
3. Then start playing the animation in the code
1 ((animationdrawable) Img.getbackground ()). Start ();
//=============
Example: Frame animation
:
Demo1\app\src\main\res\drawable\anim_frame.xml
1 <?XML version= "1.0" encoding= "Utf-8"?>2 <animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:oneshot= "false">4 <Item5 android:drawable= "@drawable/aa"6 android:duration= "$" />7 <Item8 android:drawable= "@drawable/bb"9 android:duration= "$" />Ten <Item One android:drawable= "@drawable/cc" A android:duration= "$" /> - <Item - android:drawable= "@drawable/dd" the android:duration= "$" /> - <Item - android:drawable= "@drawable/ee" - android:duration= "$" /> + <Item - android:drawable= "@drawable/ff" + android:duration= "$" /> A </animation-list>
Demo1\app\src\main\res\layout\activity_main.xml
1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context=". Mainactivity ">6 7 <ImageView8 Android:id= "@+id/main_img"9 Android:layout_width= "100DP"Ten Android:layout_height= "180DP" One Android:layout_centerhorizontal= "true" A android:layout_centervertical= "true" - Android:background= "@drawable/anim_frame"/> - </Relativelayout>
Demo1\app\src\main\java\com\ly\demo1\mainactivity.java
1 Package Com.ly.demo1;2 3 import android.app.Activity;4 import android.graphics.drawable.AnimationDrawable;5 import Android.os.Bundle;6 import Android.widget.ImageView;7 8 Public class Mainactivity extends Activity {9 private ImageView img;Ten One @Override A protected void OnCreate (Bundle savedinstancestate) { - super.oncreate (savedinstancestate); - Setcontentview (r.layout.activity_main); the img = (ImageView) Findviewbyid (r.id.main_img); - ( (animationdrawable) Img.getbackground ()). Start (); - } - +}
Frames-per-frame animation (Frame-by-frame animations)