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.