Android Frame Animation

Source: Internet
Author: User

I. Setting frame animations in an XML file

1, first you have to create a animation_list file under the Drawable resource folder

<?xml version= "1.0" encoding= "Utf-8"? ><animation-list xmlns:android= "http://schemas.android.com/apk/res/ Android ">    <item        android:drawable=" @drawable/p1 "        android:duration="/> <item        android:drawable= "@drawable/p2"        android:duration= "/>    <item        android:drawable=" @ Drawable/p3 "        android:duration="/>    <item        android:drawable= "@drawable/p4"        android: Duration= ""/>    <item        android:drawable= "@drawable/p5" android:duration=        " Animation-list>

2. Load the animation into space via Java code startup and start

ImageView imageview= (ImageView) Findviewbyid (R.ID.ID_IV); Imageview.setimageresource (r.drawable.anim_list); Animationdrawable animationdrawable = (animationdrawable) image.getdrawable (); Animationdrawable.setoneshot (false) ;//Whether to execute only once Animationdrawable.start ();//Start animation//animationdrawable.stop ();//Stop animation

  

Second, set the frame animation in Java code

ImageView imageview= (ImageView) Findviewbyid (R.ID.ID_IV); animationdrawable= new Animationdrawable (); Animationdrawable.addframe (Getresources (). Getdrawable (R.DRAWABLE.P1), and Animationdrawable.addframe ( Getresources (). Getdrawable (R.DRAWABLE.P2), imageview.setimagedrawable (Animationdrawalbe); Animationdrawable.setoneshot (false);//whether to execute only once Animationdrawable.start ();//Start animation//animationdrawable.stop ();//Stop animation

  

  

  

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