Android platform provides two kinds of animation is a frame animation, that is, the sequential playback of pre-made images, and GIF pictures or the principle of the film is similar to the theory, the other is the tween animation, is the scene of the object constantly changing the image to produce animation effect (rotation, translation, indentation and gradient) , this article is to introduce the implementation of the first frame animation, frame animation is a common form of animation (frame by frame), the principle is the "continuous keyframe" in the decomposition of animation, that is, on each frame of the timeline to draw different content frames, so that its continuous play and animation. Because the frame sequence content of frames-per-frame animation is not the same, not only to increase the burden of production and the final output of the file volume is also very large, but its advantages are also very obvious: frame-wise animation has a very large flexibility, almost can express any want to show the content, and it is similar to the film playing mode, very suitable for performing
Layout File
First, create a new drawable folder in Res, put the picture you need to show in it, and the Fight.xml file showing the picture, the code is as follows:
<?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/fight_1 "android:duration=" "/> <item android:drawable=" @drawable/fight_2 "android:duration=",/> <item an droid:drawable= "@drawable/fight_3" android:duration= "/> <item android:drawable=" @drawable/fight _4 "android:duration=" "/> <item android:drawable=" @drawable/fight_5 "android:duration=" 20 0 "/> <item android:drawable=" @drawable/fight_6 "android:duration=" $ "/> <item Android oid:drawable= "@drawable/fight_7" android:duration= "/> <item android:drawable=" @drawable/fight_8 "android:duration=" "/> <item android:drawable=" @drawable/fight_9 "android:duration=" 200 " /> <item android:drawable= "@drawable/fight_10" android:duration= "/> <item android:drawable=" @drawable/fight_11 " android:duration= "/></animation-list>"
Layout of the folder:
Demo Implementation
Mainactivity defines a imageview, called in OnCreate:
ImageView fightimage = (ImageView) Findviewbyid (r.id.image_aniation); Fightimage.setbackgroundresource (r.drawable.fight); Fightnimation = (animationdrawable) fightimage.getbackground ();
Cannot be loaded immediately when called and needs to be called when touching:
public boolean ontouchevent (Motionevent event) { if (event.getaction () = = Motionevent.action_down) { Fightnimation.start (); return true; } Return Super.ontouchevent (event); }
The effect is as follows:
Android Animation-Frame animation