The first knowledge of Android Animationdrawable

Source: Internet
Author: User

drawable animation can load drawable resources to implement frame animations. Animationdrawable is the basic class for implementing drawable animations.

Here, we use animationdrawable to simulate the realization of dynamic graphs.

Fragment_main layout file----Just need to put a ImageView

1 <Relativelayoutxmlns:android= "Http://schemas.android.com/apk/res/android"2 Xmlns:tools= "Http://schemas.android.com/tools"3 Android:layout_width= "Match_parent"4 Android:layout_height= "Match_parent"5 Tools:context= "Com.yztc.frameanimation.MainActivity" >6 7     <ImageView8         Android:id= "@+id/iv_frame"9 Android:layout_width= "Match_parent"Ten Android:layout_height= "200DP" One Android:background= "@drawable/girl_and_boy" /> A  - </Relativelayout>
Fragment_main

Girl_and_boy layout file----Implementation Animations

It is recommended to implement drawable animations using XML files, which is not recommended in code. This XML file is stored in the res/drawable/directory in the project. The directives (that is, attributes) of an XML file are the order and time interval in which the animation plays.

1 <?XML version= "1.0" encoding= "Utf-8"?>2 <animation-listxmlns:android= "Http://schemas.android.com/apk/res/android" >3     <!--The Onshot property indicates that the animation executes only once -4     5     <!--Duration = Duration -6     <Item7         android:drawable= "@drawable/girl_1"8 android:duration= "$">9     </Item>Ten     <Item One         android:drawable= "@drawable/girl_2" A android:duration= "$"> -     </Item> -     <Item the         android:drawable= "@drawable/girl_3" - android:duration= "$"> -     </Item> -     <Item +         android:drawable= "@drawable/girl_4" - android:duration= "$"> +     </Item> A     <Item at         android:drawable= "@drawable/girl_5" - android:duration= "+"> -     </Item> -     <Item -         android:drawable= "@drawable/girl_6" - android:duration= "The "> in     </Item> -     <Item to         android:drawable= "@drawable/girl_7" + android:duration= "$"> -     </Item> the     <Item *         android:drawable= "@drawable/girl_8" $ android:duration= "The ">Panax Notoginseng     </Item> -     <Item the         android:drawable= "@drawable/girl_9" + android:duration= "+"> A     </Item> the     <Item +         android:drawable= "@drawable/girl_10" - android:duration= "$"> $     </Item> $     <Item -         android:drawable= "@drawable/girl_11" - android:duration= "$"> the     </Item> - Wuyi </animation-list>
Girl_and_boy

Mainactivity

1  Packagecom.dragon.android.initgif;2 3 Importandroid.app.Activity;4 Importandroid.graphics.drawable.AnimationDrawable;5 ImportAndroid.os.Bundle;6 ImportAndroid.widget.ImageView;7 8  Public classMainactivityextendsActivity {9 Ten @Override One     protected voidonCreate (Bundle savedinstancestate) { A         Super. OnCreate (savedinstancestate); - Setcontentview (r.layout.fragment_main); -  theImageView Ivframe =(ImageView) Findviewbyid (r.id.iv_frame); -         //get an animated picture -animationdrawable background =(animationdrawable) ivframe - . Getbackground (); +         //Start Playback - Background.start (); +         //The stop method. A         //background.stop (); at     } -  -}

Picture material

Girl_1.gif Girl_2.gif Girl_3.gif

Girl_4.gif Girl_5.gif Girl_6.gif

Girl_7.gif Girl_8.gif Girl_9.gif

Girl_10.gif Girl_11.gif

The first knowledge of Android Animationdrawable

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.