frame animation: refers to a number of pictures quickly switch
Let's look at the effect of the implementation
Implementation method
Step one: Create an Android project using Android Studio, and add a picture of each frame used to create frame animations in the Drawable folder
Step Two: Create a new Frameanimation.xml file under the Drawable folder and add the following code in Frameannimation.xml
<?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/g1 "android:duration=" $ "/> <ite M android:drawable= "@drawable/g2" android:duration= "/> <item android:drawable=" @drawable/g3 "Android: duration= "/> <item android:drawable=" @drawable/g4 "android:duration=" $ "/> <item android:drawable = "@drawable/g5" android:duration= "/> <item android:drawable=" @drawable/g6 "android:duration="/> " Lt;item android:drawable= "@drawable/g7" android:duration= "$"/> <item android:drawable= "@drawable/g8" android:duration= "/> <item android:drawable=" @drawable/g9 "android:duration="/> <item android: drawable= "@drawable/g10" android:duration= "/> <item android:drawable=" @drawable/g11 "android:duration=" "/></animation-list>
Step Three:Modify the Activity_main.xml file
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " xmlns:tools=" Http://schemas.android.com/tools " android:layout_width=" Match_parent " android:layout_height= "Match_parent" tools:context= "com.fyt.frameanimation.MainActivity" android:o rientation= "vertical" > <imageview android:id= "@+id/iv" android:layout_width= "Wrap_content" android:layout_height= "Wrap_content"/></linearlayout>
Last step: Modify the Mainactivity.java file
Package Com.fyt.frameanimation;import Android.app.activity;import android.graphics.drawable.AnimationDrawable; Import Android.os.bundle;import Android.widget.imageview;public class Mainactivity extends Activity { @Override protected void OnCreate (Bundle savedinstancestate) { super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); Get the ImageView control on the layout file ImageView IV = (ImageView) Findviewbyid (R.ID.IV); The resource file of the frame animation is specified as the background Iv.setbackgroundresource (r.drawable.frameanimation) of the ImageView; Gets the background of the ImageView animationdrawable ad = (animationdrawable) iv.getbackground (); Play frame animation Ad.start ();} }
Use frame motion in Android