How does Android Play multiple images to form an animation?
In Android, you can play an image frame by frame, and then produce a dynamic effect. Prepare several consecutive images, create an anim folder under the res folder of the source program, and create an XML file.
The XML Code is as follows:
- Version = "1.0" encoding = "UTF-8"?> Xmlns: android = "http://schemas.android.com/apk/res/android"
- Android: oneshot = "true"> Android: drawable = "@ drawable/c1" android: duration = "200" />
- Android: drawable = "@ drawable/c2" android: duration = "200" /> Android: drawable = "@ drawable/c3" android: duration = "200" />
- Android: drawable = "@ drawable/c4" android: duration = "200" /> Android: drawable = "@ drawable/c5" android: duration = "200" />
- Android: drawable = "@ drawable/c6" android: duration = "200" />
C1, c2, c3, c4, c5, and c6 are the names of the added images.
Place an ImageView control in the form and write it in the Code:
_ ImageView1 = (ImageView) findViewById (R. id. imageView1); // The placed ImageView Control
- // Set the animation background _ imageView1.setBackgroundResource (R. anim. animation_list); // Where R. anim. animation_list is the Resource Name of the animation description file prepared in the previous step.
- // Obtain the animation object _ animaition = (AnimationDrawable) _ imageView1.getBackground ();
- Finally, you can start the animation. The Code is as follows: // do you want to start the animation only once?
- _ Animaition. setOneShot (False);If(_ Animaition. isRunning () // Is it running?
- {_ Animaition. stop (); // stop
- } _ Animaition. start (); // start