Frame Animation:
1. Find a group of images c01.jpg, c02.jpg, c03.jpg, c04.jpg, c05.jpg, and copy them to the res/drawable directory;
2. Create an XML file in the res/drawable Directory: frame_anim.xml
[Html]
<? 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/c01" android: duration = "500"/>
<Item android: drawable = "@ drawable/c02" android: duration = "500"/>
<Item android: drawable = "@ drawable/c03" android: duration = "500"/>
<Item android: drawable = "@ drawable/c04" android: duration = "500"/>
<Item android: drawable = "@ drawable/c05" android: duration = "500"/>
</Animation-list>
<? 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/c01" android: duration = "500"/>
<Item android: drawable = "@ drawable/c02" android: duration = "500"/>
<Item android: drawable = "@ drawable/c03" android: duration = "500"/>
<Item android: drawable = "@ drawable/c04" android: duration = "500"/>
<Item android: drawable = "@ drawable/c05" android: duration = "500"/>
</Animation-list> 3. Create an XML file in the res/layout Directory: frame_anim_layout.xml
[Html]
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<ImageView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: scaleType = "centerInside"
Android: id = "@ + id/imgFrame"
Android: background = "@ drawable/frame_anim"> </ImageView>
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">
<Button
Android: text = ""
Android: id = "@ + id/btnStart"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1.0" type = "codeph" text = "codeph"> </Button type = "codeph" text = "/codeph">
<Button
Android: text = "end"
Android: id = "@ + id/btnEnd"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1.0" type = "codeph" text = "codeph"> </Button type = "codeph" text = "/codeph">
</LinearLayout>
</LinearLayout>
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout
Xmlns: android = "http://schemas.android.com/apk/res/android"
Android: orientation = "vertical"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent">
<ImageView
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: scaleType = "centerInside"
Android: id = "@ + id/imgFrame"
Android: background = "@ drawable/frame_anim"> </ImageView>
<LinearLayout
Android: layout_width = "match_parent"
Android: layout_height = "wrap_content">
<Button
Android: text = ""
Android: id = "@ + id/btnStart"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1.0" type = "codeph" text = "codeph"> </Button type = "codeph" text = "/codeph">
<Button
Android: text = "end"
Android: id = "@ + id/btnEnd"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: layout_weight = "1.0" type = "codeph" text = "codeph"> </Button type = "codeph" text = "/codeph">
</LinearLayout>
</LinearLayout> 4. Code in the Activity file:
[Java]
Package com. bison;
Import android. app. Activity;
Import android. graphics. drawable. AnimationDrawable;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. ImageView;
Public class AnimationDemoActivity extends Activity implements OnClickListener {
// Start button
Private Button btnStart;
// End button
Private Button btnEnd;
Private ImageView imgFrame;
// Declare the Frame Animation object
Private AnimationDrawable frameAnim;
/** Initialization */
Public void init (){
BtnStart = (Button) findViewById (R. id. btnStart );
BtnEnd = (Button) findViewById (R. id. btnEnd );
BtnStart. setOnClickListener (this );
BtnEnd. setOnClickListener (this );
ImgFrame = (ImageView) findViewById (R. id. imgFrame );
// Declare the backgroud of ImageView to the Frame animation object
FrameAnim = (AnimationDrawable) imgFrame. getBackground ();
}
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// Load the layout. frame_anim_layout page
SetContentView (R. layout. frame_anim_layout );
Init ();
}
Public void onClick (View v ){
// Determine button events
Switch (v. getId ()){
Case R. id. btnStart:
FrameAnim. start ();
Break;
Case R. id. btnEnd:
FrameAnim. stop ();
Break;
}
}
}
Package com. bison;
Import android. app. Activity;
Import android. graphics. drawable. AnimationDrawable;
Import android. OS. Bundle;
Import android. view. View;
Import android. view. View. OnClickListener;
Import android. widget. Button;
Import android. widget. ImageView;
Public class AnimationDemoActivity extends Activity implements OnClickListener {
// Start button
Private Button btnStart;
// End button
Private Button btnEnd;
Private ImageView imgFrame;
// Declare the Frame Animation object
Private AnimationDrawable frameAnim;
/** Initialization */
Public void init (){
BtnStart = (Button) findViewById (R. id. btnStart );
BtnEnd = (Button) findViewById (R. id. btnEnd );
BtnStart. setOnClickListener (this );
BtnEnd. setOnClickListener (this );
ImgFrame = (ImageView) findViewById (R. id. imgFrame );
// Declare the backgroud of ImageView to the Frame animation object
FrameAnim = (AnimationDrawable) imgFrame. getBackground ();
}
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// Load the layout. frame_anim_layout page
SetContentView (R. layout. frame_anim_layout );
Init ();
}
Public void onClick (View v ){
// Determine button events
Switch (v. getId ()){
Case R. id. btnStart:
FrameAnim. start ();
Break;
Case R. id. btnEnd:
FrameAnim. stop ();
Break;
}
}
}
PS: The Frame animation principle is similar to the film. When a scene or scene passes through, the human's vision changes rapidly during the pause period to form a group chart and generate an animation.
From today and now... Bi... Column