Objective
Must have used the United States Group client user to the American regiment that loaded villain animation impression is very deep, a cute villain in that desperately run. This animation implementation of the method is actually a lot, today here with frame animation to achieve.
One
Second, the layout file
<relativelayout 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 " android:paddingbottom= "@dimen/activity_vertical_margin" android:paddingleft= "@dimen/activity_ Horizontal_margin " android:paddingright=" @dimen/activity_horizontal_margin " android:paddingtop=" @dimen /activity_vertical_margin " tools:context=". Mainactivity "> <imageview android:id=" @+id/imageview " android:layout_width=" Fill_parent " android:layout_height= "fill_parent" android:onclick= "Start" android:scaletype= "Fitcenter" android:src= "@anim/frame"/></relativelayout>
Create a new Anim file, which is stored in the picture to prepare frame animation, the picture can be directly to the United States Regiment of the installation package to be extracted.
<?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/progress_loading_image_01 " android:duration= "/> <item android:drawable=" @drawable/progress_loading_image_02 "android:duration= "/></animation-list>"
Main function Code:
Using the Getdrawabel method of image view to get a Animationdrawable object and then call the Start method to start the animation.
public class Mainactivity extends Activity {private ImageView imageview;private animationdrawable ad; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_ Main); ImageView = (ImageView) Findviewbyid (r.id.imageview); ad = (animationdrawable) imageview.getdrawable ();//Get Picture content , strongly converted to animated object}public void Start (View v) {if (ad.isrunning ()) ad.stop (); Ad.start ();//Start Playback}}
Android App--imitation American loading loading animation