Android animationdrawable animation and app launch, load boot page (screen)
Animationdrawable is an Android frame animation that can simply be thought of as a animationdrawable to load a series of resource images as "movies". Now, in some apps, it's often necessary to load a few boot pages (posters, decorations, sponsored ads, etc.) before the app cuts into the theme, which have two common features:
(1) is not the focus of the app, but just like a booth to show some pictures.
(2) The front, the current, after the page basically no special need to deal with the interaction design (because just play a few or several frames), and then jump into the app's content.
Now give a sample demo to implement a simple example: An app's mainactivity starts, looping through 3 images.
(The 1th Step) first place in the Res/drawable directory in advance to play the picture resources.
(2nd Step) in the Res/anim directory to build animation-list XML code file, assuming this code file is called My_animation.xml,,
The specific code content of the file:
<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "> <item android:drawable=" @drawable/p1 " android:duration=" "/> <item android:drawable= "@drawable/p2" android:duration= "/> <item android:drawable=" @ Drawable/p3 " android:duration=" "/></animation-list>"
The item's resource picture P1,P2,P3 will be played sequentially. The value of android:duration (in milliseconds) is the duration of the item's playback, and in this case, the picture is displayed for a period of time.
(3rd) In the Activity load layout file Activity_main.xml write a imageview, set the ImageView android:src= 2nd step to create a good my_animation.xml.
<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 " android:orientation= "vertical" > <button android:id= "@+id/play" android:layout_width= " Wrap_content " android:layout_height=" wrap_content " android:text=" @string/play "/> <button android:id= "@+id/stop" android:layout_width= "wrap_content" android:layout_height= "wrap_content " android:text=" @string/stop "/> <imageview android:id=" @+id/imegaview " android: Layout_width= "Match_parent" android:layout_height= "wrap_content" android:src= "@anim/my_animation"/ > </LinearLayout>
Here, the completion of the design, the activity starts, will be in the ImageView inside the play animation, of course, you can do more, for this animation to add some control buttons (play,stop), control play (play) or stop (stop).
Activity:MainActivity.java of the test:
Package Zhangphil.animation;import Android.support.v7.app.actionbaractivity;import Android.view.view;import Android.widget.button;import Android.widget.imageview;import Android.graphics.drawable.animationdrawable;import Android.os.bundle;public class Mainactivity extends Actionbaractivity {privateanimationdrawable mAnimationDrawable= null; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (R.layout.activity_main); ImageView imageview= (ImageView) Findviewbyid (R.id.imegaview); Manimationdrawable= (animationdrawable) imageview.getdrawable (); Button play= (button) Findviewbyid (r.id.play);p Lay.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View v) {Manimationdrawable.start ();}}); Button stop= (button) Findviewbyid (r.id.stop); Stop.setonclicklistener (new View.onclicklistener () {@Overridepublic void OnClick (View v) {manimationdrawable.stop ();}});}}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced. Reprint Please specify source: Http://blog.csdn.net/zhangphil
Android animationdrawable animation and App launch boot page