Document directory
- Simple Animation:
- Put images in the drawable directory,
- Create an xml file frame. xml and save the image as follows:
- Then define a layout frame_layout.xml:
- Then write the activity class, FrameActivity. java:
- At this point, you can run and implement it after registering in the list.
Simple Animation: add images to the drawable directory,
Create an xml file frame. xml and save the image as follows:
<? Xml version = "1.0" encoding = "UTF-8"?> <Animation-list xmlns: android = "http://schemas.android.com/apk/res/android" android: oneshot = "false"> <! -- Can be added repeatedly to implement loop --> <! -- Android: duration = "100" sets the duration of the image --> <item android: drawable = "@ drawable/girl_1" android: duration = "100"/> <item android: drawable = "@ drawable/girl_2" android: duration = "100"/> <item android: drawable = "@ drawable/girl_3" android: duration = "100"/> <item android: drawable = "@ drawable/girl_4" android: duration = "100"/> <item android: drawable = "@ drawable/girl_5" android: duration = "100"/> <item android: drawable = "@ drawable/girl_6" android: duration = "200"/> <item android: drawable = "@ drawable/girl_7" android: duration = "300"/> <item android: drawable = "@ drawable/girl_6" android: duration = "200"/> <item android: drawable = "@ drawable/girl_7" android: duration = "300"/> <item android: drawable = "@ drawable/girl_8" android: duration = "200"/> <item android: drawable = "@ drawable/girl_9" android: duration = "100"/> <item android: drawable = "@ drawable/girl_10" android: duration = "100"/> <item android: drawable = "@ drawable/girl_11" android: duration = "100"/> </animation-list>
Then define a layout frame_layout.xml:<? 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" android: gravity = "center"> <! -- Bearer image --> <ImageView android: id = "@ + id/frameIV" android: layout_width = "wrap_content" android: layout_height = "wrap_content"/> </LinearLayout>
Then write the activity class, FrameActivity. java:Package cn. class3g. animation; import android. app. activity; import android. graphics. drawable. animationDrawable; import android. OS. bundle; import android. view. motionEvent; import android. widget. imageView; public class FrameActivity extends Activity {AnimationDrawable attackAnimation; // define the animation object ImageView frameIV; protected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); this. setContentView (R. layout. frame_layout); init ();} private void init () {frameIV = (ImageView) this. findViewById (R. id. frameIV); frameIV. setBackgroundResource (R. drawable. frame); // get the image and add it to the layout (as a background image) attackAnimation = (AnimationDrawable) frameIV. getBackground (); // get the background image to the animation object} // trigger public boolean onTouchEvent (MotionEvent event) {if (event. getAction () = MotionEvent. ACTION_DOWN) {attackAnimation. start (); // click the screen to start the animation} return super. onTouchEvent (event );}}
At this point, you can run and implement it after registering in the list.