1. Set the background
A. Create an anim folder in res and create the animation_list.xml file in this folder.
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Animation-list xmlns: android = "http://schemas.android.com/apk/res/android"
Android: oneshot = "true">
<Item
Android: drawable = "@ drawable/c1"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c2"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c3"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c4"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c5"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c6"
Android: duration = "200"/>
</Animation-list>
B. layout File
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
<ImageView
Android: id = "@ + id/imageView1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerHorizontal = "true"
Android: paddingTop = "50dp">
</ImageView>
<Button
Android: id = "@ + id/button2"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: text = "Run"
Android: onClick = "run">
</Button>
</LinearLayout>
C. java code
[Java]
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
This. setContentView (R. layout. contextmenu );
ImageView = (ImageView) findViewById (R. id. imageView1 );
ImageView. setBackgroundResource (R. anim. animation_list );
Draw = (AnimationDrawable) imageView. getBackground ();
// Draw = (AnimationDrawable) imageView. getDrawable ();
}
[Java]
Public void run (View v ){
If (draw. isRunning ()){
Draw. stop ();
} Else {
Draw. stop ();
Draw. start ();
}
}
2. Set the SRC Mode
A. Create an anim folder in res and create the animation_list.xml file in this folder.
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Animation-list xmlns: android = "http://schemas.android.com/apk/res/android"
Android: oneshot = "true">
<Item
Android: drawable = "@ drawable/c1"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c2"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c3"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c4"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c5"
Android: duration = "200"/>
<Item
Android: drawable = "@ drawable/c6"
Android: duration = "200"/>
</Animation-list>
B. layout File
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: orientation = "vertical">
<ImageView
Android: id = "@ + id/imageView1"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_centerHorizontal = "true"
Android: src = "@ anim/animation_list"
Android: paddingTop = "50dp">
</ImageView>
<Button
Android: id = "@ + id/button2"
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: layout_alignParentBottom = "true"
Android: text = "Run"
Android: onClick = "run">
</Button>
</LinearLayout>
C. layout File
[Java]
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
This. setContentView (R. layout. contextmenu );
ImageView = (ImageView) findViewById (R. id. imageView1 );
ImageView. setBackgroundResource (R. anim. animation_list );
// Draw = (AnimationDrawable) imageView. getBackground ();
Draw = (AnimationDrawable) imageView. getDrawable ();
RegisterForContextMenu (text );
}
[Java]
Public void run (View v ){
If (draw. isRunning ()){
Draw. stop ();
} Else {
Draw. stop ();
Draw. start ();
}
}
From Snowball