Android's animationdrawable Simple simulation dynamic diagram _android

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 implementation of the dynamic graph simply.

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

<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"
  xmlns:tools= "http:// Schemas.android.com/tools "
  android:layout_width=" match_parent "
  android:layout_height=" Match_parent "
  tools:context= "com.yztc.frameanimation.MainActivity" >

  <imageview
    android:id= "@+id/iv_frame"
    android:layout_width= "match_parent"
    android:layout_height= "200DP"
    android:background= "@drawable Girl_and_boy "/>

</RelativeLayout>

Girl_and_boy Layout File----animation

The method of XML file is recommended to implement drawable animation, which is not recommended to be implemented in code. This XML file is stored in the res/drawable/directory of the project. The instruction (that is, the attribute) of an XML file is the order and time interval in which the animation is played.

<?xml version= "1.0" encoding= "Utf-8"?> <animation-list xmlns:android= "http://schemas.android.com/apk/res/" The Android > <!--onshot property indicates that the animation executes only once--> <!--duration represents duration--> <item android:drawable= "@dr Awable/girl_1 "android:duration=" > </item> <item android:drawable= "@drawable/girl_2" Andro
  id:duration= "> </item> <item android:drawable=" @drawable/girl_3 "android:duration=" "> 
    </item> <item android:drawable= "@drawable/girl_4" android:duration= "> </item> <item android:drawable= "@drawable/girl_5" android:duration= "> </item> <item android:drawable=" @ Drawable/girl_6 "android:duration=" > </item> <item android:drawable= "@drawable/girl_7" and
  roid:duration= "> </item> <item android:drawable=" @drawable/girl_8 "android:duration=" >
    </item> <itemandroid:drawable= "@drawable/girl_9" android:duration= "> </item> <item android:drawable=" @drawa Ble/girl_10 "android:duration=" > </item> <item android:drawable= "@drawable/girl_11" Androi
 d:duration= "> </item> </animation-list>"

Mainactivity

Package com.dragon.android.initgif;

Import android.app.Activity;
Import android.graphics.drawable.AnimationDrawable;
Import Android.os.Bundle;
Import Android.widget.ImageView;

public class Mainactivity extends activity {

  @Override
  protected void onCreate (Bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    Setcontentview (r.layout.fragment_main);

    ImageView ivframe = (imageview) Findviewbyid (r.id.iv_frame);
    Get an animated picture of
    animationdrawable background = (animationdrawable) ivframe
        . Getbackground ();
    Start playing
    Background.start ();
    Stop the method.
    Background.stop ();
  }


The above is the entire content of this article, I hope to help you learn, but also hope that we support the cloud habitat community.

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.