There are several main types of animations in Android, frame animations (frames), motion tweens (tween), property animations
The main use of our project is frame animation and motion tweens
Frame animation requires us to prepare a set of static pictures, which are derived from the decomposition of the animation, the static picture is linked to play to form an animated effect
We create a new drawable directory under the Res directory to hold animation resources and XML files
The picture is as follows:
650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M00/30/E7/wKiom1Ophl6Rj-aUAAGKnSDnP9M410.jpg "title=" 2.png " alt= "Wkiom1ophl6rj-auaagknsdnp9m410.jpg"/>
Girl.xml Note android:oneshot= "False|true" This property controls whether the animation plays repeatedly, false indicates repeated playback
<?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/girl_1 " android:duration="/> <item android:drawable= "@drawable/girl_2" android:duration= "/> <item " android:drawable= "@drawable/girl_3" android:duration= "/> <item " android:drawable= "@drawable/girl_4" android: duration= "/>&NBSP;&NBSP;&NBSP;&NBSP"; <item android:drawable= "@drawable/girl_5" android:duration= "/> <item " android:drawable= "@drawable/girl_6" android:duration= "/> <item " android:drawable= "@drawable/girl_7" android:duration= "400 "/> <item android:drawable=" @ Drawable/girl_8 " android:duration="/> <item android:drawable= "@drawable/girl_9" android:duration= "/> <item " android:drawable= "@drawable/girl_10" android:duration= " "/> <item android:drawable=" @ Drawable/girl_11 " android:duration="/></ Animation-list>
Mainactivity.java
package com.example.frameanim;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.ImageView;public class Mainactivity extends activity {private imageview iv;private animationdrawable mAnimationDrawable; @Overrideprotected void oncreate (bundle savedinstancestate) { Super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main);iv = (ImageView) Findviewbyid (R.ID.IV); Iv.setbackgroundresource (R.drawable.girl); // Set the XML animation resource to ImageView background manimationdrawable = (animationdrawable) iv.getbackground (); // Gets the animated iv.setonclicklistener of the settings (New onclicklistener () {@Overridepublic void onclick ( VIEW&NBSP;V) {if (!manimationdrawable.isrunning ()) {manimationdrawable.start ();} else if (Manimationdrawable.isrunning ()) {manimationdrawable.stop ();}});}}