android animation frame animation

Frame animation

The so-called frame animation is that multiple pictures are played continuously.

1. Create resource files under drawable

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">

    <!-- oneshot 是否重复
        duration 持续时间 毫秒
        drawable 引用图片

    -->
    <item android:duration="100" android:drawable="@drawable/one"></item>
    <item android:duration="100" android:drawable="@drawable/two"></item>
    <item android:duration="100" android:drawable="@drawable/three"></item>
    <item android:duration="100" android:drawable="@drawable/four"></item>
    <item android:duration="100" android:drawable="@drawable/five"></item>

</animation-list>

1, Set properties to ImageView

不是src 是backgroud的属性哦.
 <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/img"
        android:background="@drawable/pic">
 </ImageView>

3, define the animation properties

private AnimationDrawable animationDrawable;

4. How to use

//帧动画
 animationDrawable = (AnimationDrawable) img.getBackground();
 
 //启动
 animationDrawable.start();
 
 //停止
 animationDrawable.stop();

Guess you like

Origin blog.csdn.net/shuai_ge_feng/article/details/105256220