帧动画DrawableAnimation

简介

逐帧动画就是一个接一个地加载一系列可绘制的资源来创建一个动画。这是一种传统的动画,从某种意义上说,它是由一系列不同的图像组成的,按照顺序播放,就像一卷电影。drawable 动画,即帧动画:

1 定义xml文件,加载帧动画

在res/drawable/目录下新建一个animation-list动画资源文件

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    //false循环播放 true播放结束后停止
    android:oneshot="false" >   

    <item android:duration="500" android:drawable="@drawable/ic_heart_0"></item>
    <item android:duration="500" android:drawable="@drawable/ic_heart_25"></item>
    <item android:duration="500" android:drawable="@drawable/ic_heart_50"></item>
    <item android:duration="500" android:drawable="@drawable/ic_heart_75"></item>
    <item android:duration="500" android:drawable="@drawable/ic_heart_100"></item> 

</animation-list>

2 设置imageview资源

<ImageView
        android:id="@+id/frame_iv"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/frameanimation"/>

3 开启动画

ImageView mImageView=(ImageView) findViewById(R.id.frame_iv);
AnimationDrawable mDrawable = (AnimationDrawable) mImageView.getDrawable();
mDrawable.start();

优缺点: 帧动画可以实现比较复杂而酷炫的动画,但是因为加载的是图片资源,对于内存以及UI的性能损耗较大。使用时需慎重考虑。

posted @ 2016-03-21 17:09  随易来了  阅读(192)  评论(0编辑  收藏  举报