Android动画——帧动画

0.介绍

——就是影像动画中最小单位的单幅影像画面,相当于电影胶片上的每一格镜头。 一就是一副静止的画面,连续的就形成动画,如电视图象

帧动画的意思就是逐帧播放的动画,属于View动画的一种,可以实现一种动画片似的效果。

1.使用

(1) 首先将要播放的图片放到drawable目录,按照播放顺序排好序。
(2) 在drawable目录下新建一个xml文件,并写下如下代码:

  • android:oneshot="false" 表示循环播放,“true”表示画只播放一次停止在最后一帧上;

  • 每一个item代表一帧;drawable指定这一帧的图片资源id;duration代表这一帧完成的时间,或者说是停留的时间,单位是毫秒。

    // res/drawable/frame_animation.xml
    <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
    android:oneshot="false">
    <item android:drawable="@drawable/d1" android:duration="100"/>
    <item android:drawable="@drawable/d2" android:duration="100"/>
    <item android:drawable="@drawable/d3" android:duration="100"/>
    <item android:drawable="@drawable/d4" android:duration="100"/>
    <item android:drawable="@drawable/d5" android:duration="100"/>
    <item android:drawable="@drawable/d6" android:duration="100"/>
    <item android:drawable="@drawable/d7" android:duration="100"/>
    <item android:drawable="@drawable/d8" android:duration="100"/>
    </animation-list>

在Java代码中使用上面定义的文件

Button mButton = (Button)findViewById(R.id.button);
mButton.setBackgroundResource(R.drawable.frame_animation);
AnimationDrawable drawable = (AnimationDrawable)mButton.getBackground();
drawable.start();

2.运行效果

wqe.gif

真实效果比这个好看,mp4转成gif 有点不流畅了(第一次这样转可能不熟练)

3. 注意

如果图片太大会在成 OOM

4. 感谢

《Android 开发艺术探索》

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容