Android Frame Animation detailed

Source: Internet
Author: User

In the previous article we said that Android tween animation, this one we say frame animation, frame animation is to achieve a similar to the effect of GIF animation, is a number of images in a predetermined time sequential display sequentially.
Create a new Android project, named Frametest, create a new folder under the Res folder called Anim, the XML file of our frame animation is placed here.
Create a new Frame.xml file in Anim with the following contents:

<?xml version= "1.0" encoding= "Utf-8"?><animation-list xmlns:android="Http://schemas.android.com/apk/res/android" android:oneshot="false">    <!--True to play only once, false to play an infinite loop--    <item android:drawable="@drawable/girl_1" android:duration="100" />    <item android:drawable= "@drawable/girl_2" android:duration=" " />    <item android:drawable="@drawable/girl_3" android:duration= "/>"     <item android:drawable="@drawable/girl_4" android:duration="100" />    <item android:drawable= "@drawable/girl_5" android:duration=" " />    <item android:drawable="@drawable/girl_6" android:duration= "/>"     <item android:drawable="@drawable/girl_7" android:duration="400" />    <item android:drawable= "@drawable/girl_8" android:duration=" " />    <item android:drawable="@drawable/girl_9" android:duration= "/>"     <item android:drawable="@drawable/girl_10" android:duration="100" />    <item android:drawable= "@drawable/girl_11" android:duration=" " /></animation-list>

Here is the 11 picture, the previous Android:oneshot property indicates the number of times the animation was executed, false means that the animation repeats itself repeatedly, True indicates that the animation value plays once, and duration indicates the time, in milliseconds, that each picture is displayed.

Then look at the code in Mainactivity:

 Public  class mainactivity extends Activity {    PrivateImageView IV;PrivateAnimationdrawable AD;@Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate);        Setcontentview (R.layout.activity_main); IV = (ImageView) This. Findviewbyid (R.ID.IV);//Iv.setbackgroundresource (r.anim.frame);//AD = (animationdrawable) iv.getbackground ();        //Above two sentences, can be replaced by the following two sentences, the effect is the sameIv.setimageresource (R.anim.frame);    AD = (animationdrawable) iv.getdrawable (); } Public void Start(View v) {//If AD is running, let it stop first        if(Ad.isrunning ()) ad.stop ();    Ad.start (); }}

First get a imageview, and then set the frame animation to its background, and finally get the background of the picture and strong to animationdrawable, when clicked on the picture, if the animation is already running, let it stop first, and then rerun, otherwise directly run can.

Android Frame Animation detailed

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.