Android Animation-Frame animation

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.