Tian Jian, gentleman to self-improvement. --"Zhou Yi Hus Elephant"
This lecture: Frame-by- frames animation frame Animation
frame-by-frames animation frame animation that a frame of a frame of the link to play will become an animation, It 's very similar to the mechanism for putting movies.
Let's feel it through a sample, and the code is written in a stare.
The following is the Res/layout/activity_main.xml layout file:
<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" tools:context= "Com.example.text.mainactivity$placeholderfragment" > <imageview android:id= "@+id/frame_image" android:layout_width= "match_parent" android:layout_ height= "Match_parent" android:layout_weight= "1"/> <button android:id= "@+id/start" Android:layout_width= "Match_parent" android:layout_height= "wrap_content" android:text= "RunFrame"/ > <button android:id= "@+id/stop" android:layout_width= "match_parent" android:layout_ height= "Wrap_content" android:text= "Stopframe"/></linearlayout>
The following is a new Res/anim/frame.xml file
<?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/b1 "android:duration=" 300 "/ > <item android:drawable= "@drawable/b2" android:duration= "/> <item android:drawable=" @ Drawable/b3 "android:duration=" "/> <item android:drawable=" @drawable/b4 "android:duration="/>
B1, B2, B3, B4 are four different little fox icons
The following is the Mainactivity.java main interface file:
public class Mainactivity extends Activity implements Onclicklistener {Private button start;private button stop;private Im Ageview IV; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (r.layout.activity_main); iv = (ImageView) Findviewbyid (r.id.frame_image); start = (Button) Findviewbyid (r.id.start); stop = (Button) Findviewbyid (r.id.stop); Start.setonclicklistener (this); Stop.setonclicklistener (This) ; Iv.setbackgroundresource (r.anim.frame);} @Overridepublic void OnClick (View v) {animationdrawable anim = (animationdrawable) iv.getbackground (); switch (V.getid () {Case r.id.start://invokes animation to draw an object's start Play Method Anim.start (); break;case r.id.stop://call the animation to draw the object's stop playback method anim.stop (); break;}}
The following are the results of the execution:
Ben said here, thank you!
30th: Android Animation (v)