android动画之帧动画

帧动画

所谓的帧动画就是多张图片连续起来播放.

1,在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, 给ImageView设置属性

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

3, 定义动画属性

private AnimationDrawable animationDrawable;

4,使用方法

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

猜你喜欢

转载自blog.csdn.net/shuai_ge_feng/article/details/105256220