Android Frames-per-frame animation play and play End action object

Source: Internet
Author: User

The XML code of the frame-wise animation:

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <animation-listxmlns:android= "Http://schemas.android.com/apk/res/android"3 Android:oneshot= "true" >4 5     <Item6         android:drawable= "@drawable/img10"7 android:duration= "+">8     </Item>9     <ItemTen         android:drawable= "@drawable/img9" One android:duration= "+"> A     </Item> -     <Item -         android:drawable= "@drawable/img8" the android:duration= "+"> -     </Item> -     <Item -         android:drawable= "@drawable/img7" + android:duration= "+"> -     </Item> +     <Item A         android:drawable= "@drawable/img6" at android:duration= "+"> -     </Item> -     <Item -         android:drawable= "@drawable/img5" - android:duration= "+"> -     </Item> in     <Item -         android:drawable= "@drawable/img4" to android:duration= "+"> +     </Item> -     <Item the         android:drawable= "@drawable/img3" * android:duration= "+"> $     </Item>Panax Notoginseng     <Item -         android:drawable= "@drawable/img2" the android:duration= "+"> +     </Item> A     <Item the         android:drawable= "@drawable/img1" + android:duration= "+"> -     </Item> $  <Item $         android:drawable= "@drawable/img0" - android:duration= "+"> -     </Item> the      - </animation-list>
View Code

The corresponding Android code:

Description:
    • Android:oneshot: The number of times the frame animation runs, true to run once, and false to play the loop;
    • Item: Defines the properties of each frame;
    • Android:drawable: Specifies the image resource corresponding to the frame;
    • Android:duration: The time at which the frame image stays.
1  Public classMainactivityextendsActivity {2 3     PrivateImageView img;4     Privatebutton button;5     Privateanimationdrawable animationdrawable;6 @Override7     protected voidonCreate (Bundle savedinstancestate) {8         Super. OnCreate (savedinstancestate);9 Setcontentview (r.layout.activity_main);Ten         intduration=0;//duration is the total time to record the first animation play Oneimg=(ImageView) Findviewbyid (R.id.imageview); A Img.setimageresource (R.drawable.item_anim); -animationdrawable=(animationdrawable) img.getdrawable (); -Img.post (NewRunnable () {//method to execute startup in an asynchronous thread the                      - @Override -                      Public voidrun () { -                         //TODO auto-generated Method Stub + Animationdrawable.start (); Start Animation -                     } +                 }); A                  for(intI=0;i<animationdrawable.getnumberofframes (); i++){ atduration+=animationdrawable.getduration (i); Calculate when an animation plays -                      -                 } -Handler handler=NewHandler (); -Handler.postdelayed (NewRunnable () { -              Public voidrun () { inIntent intent=NewIntent (mainactivity. This, Testactivity.class); Intent intent to jump to another page when the animation is done - startactivity (intent); to                  +             } - }, duration); the          *     } $ Panax Notoginseng  -}

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.