Android Animation drawable Animation

Source: Internet
Author: User

drawable animation is a frame-by-pixel animation, you must first define each frame before using it. We can either define it by code or use the XML file definition, which is generally used. As follows:

<?XML version= "1.0" encoding= "Utf-8"?><animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"Android:oneshot= "false">      <Itemandroid:drawable= "@drawable/icon_aboutus"android:duration= "$" />      <Itemandroid:drawable= "@drawable/icon_join_menu"android:duration= "$" />      <Itemandroid:drawable= "@drawable/icon_join_opinion"android:duration= "$" />  </animation-list>

where android:oneshot= "true" indicates that the animation plays only once and is equal to false when looping. The <item/> tab defines the picture that is displayed for each frame. The display order is in accordance with the <item/> definition order.

Then look at the activity of the main interface:

 Public classMainactivityextendsActivity { PublicImageView Iv_start;  PublicImageView Iv_stop;  PublicImageView iv_animation;  Publicanimationdrawable drawableanimation; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);                Setcontentview (R.layout.activity_main); Iv_start=(ImageView) Findviewbyid (R.id.iv_start); Iv_stop=(ImageView) Findviewbyid (r.id.iv_stop); Iv_animation=(ImageView) Findviewbyid (r.id.iv_animation); Iv_start.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {startanimation ();        }        }); Iv_stop.setonclicklistener (NewView.onclicklistener () {@Override Public voidOnClick (View v) {stopanimation ();        }        });          Iv_animation.setbackgroundresource (r.drawable.animations); Drawableanimation=(animationdrawable) iv_animation.getbackground (); }         Public voidstartanimation () {Drawableanimation.start (); }         Public voidstopanimation () {drawableanimation.stop (); } @Override Public BooleanOncreateoptionsmenu (Menu menu) {getmenuinflater (). Inflate (R.menu.main, menu); return true; } @Override Public Booleanonoptionsitemselected (MenuItem item) {intID =Item.getitemid (); if(id = =r.id.action_settings) {            return true; }        return Super. onoptionsitemselected (item); }}

Android Animation drawable 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.