帧动画 AnimationDrawable

帧动画是一种简单粗暴的动画;

一串图片按照一定的间隔轮流上阵就完事儿了;

在drawable中可以这样的定义;

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/ic_fp_0" android:duration="80"/>
    <item android:drawable="@drawable/ic_fp_1" android:duration="80"/>
    <item android:drawable="@drawable/ic_fp_2" android:duration="80"/>
    <item android:drawable="@drawable/ic_fp_3" android:duration="80"/>
    <item android:drawable="@drawable/ic_fp_4" android:duration="80"/>
    <item android:drawable="@drawable/ic_fp_5" android:duration="80"/>
</animation-list>

可以直接作为ImageView的src或者View背景来使用;

<ImageView
    android:layout_centerInParent="true"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/ic_fp"
     />

直接Java中强转AnimationDrawable,就可以进行控制;

AnimationDrawable mAnimationDrawable = ((AnimationDrawable)icon.getDrawable());

常用的API:

start 开始播放动画
isRunning 判断动画是否正在播放
stop 定制播放动画
setOneShot 设置动画只播放一次
isOneShot 判断是否只播放一次

猜你喜欢

转载自blog.csdn.net/weixin_39821531/article/details/89308765
今日推荐