Step by step animation of Android learning (frame)

Source: Internet
Author: User

Frame animation is to put some column pictures. Play it in turn.

Using the principle of "visual persistence" of the naked eye, the illusion of animation is given to the user, and the principle of frames-by-frame animation is the same as that of the early film.

A: You need to define a frame-wise animation that can be defined by code. can also be defined by an XML file. General XML file definition is more intuitive

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android "android:oneshot=" false "> <!--false is looping play--<!--drawables is every picture. Duration is the duration of the picture--<item android:drawable= "@drawable/g1" android:duration= "$"/> <item Android:drawa ble= "@drawable/g2" android:duration= "/> <item android:drawable=" @drawable/g3 "android:duration=" 200 "/ > <item android:drawable= "@drawable/g4" android:duration= "$"/> <item android:drawable= "@drawable/g5" android:duration= "/> <item android:drawable=" @drawable/g6 "android:duration="/> <item android: drawable= "@drawable/g7" android:duration= "/> <item android:drawable=" @drawable/g8 "android:duration=" 200 "/> <item android:drawable=" @drawable/g9 "android:duration=" "/> <item android:drawable=" @drawable/g "android:duration=" "/> <item android:drawable=" @drawabLe/g11 "android:duration="/></animation-list> 

Where oneshot represents whether the loop plays, false is looping, true is only played once

B: Set the resource defined above XMLD to the background of ImageView

        Find ImageView        ImageView IV = (ImageView) Findviewbyid (R.ID.IV);        Set the resource file of the frame animation to ImageView background        iv.setbackgroundresource (r.drawable.frameanimation);

C: Get Animationdrawable Object

        Gets the Animationdrawable object        animationdrawable ad = (animationdrawable) iv.getbackground ();

D: Start playing the animation on OK

    Start playing animation        Ad.start ();

Activity entire code:

public class Mainactivity extends Activity {    @Override    protected void onCreate (Bundle savedinstancestate) {        super.oncreate (savedinstancestate);        Setcontentview (r.layout.activity_main);            Find ImageView        ImageView IV = (ImageView) Findviewbyid (R.ID.IV);        Set the resource file of the frame animation to ImageView background        iv.setbackgroundresource (r.drawable.frameanimation);        Gets the Animationdrawable object        animationdrawable ad = (animationdrawable) iv.getbackground ();        Start playing the animation        Ad.start ();    }}

Demo Effect:


Step by step animation of Android learning (frame)

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.