赞
踩
kirk_wang的帧动画写在anim里面 我试了试写不出来。。后来看到了S丶black的写法后试着把文件写入drawable里成功
我又试着用kirk_wang的activity的代码运行了下背景图和动画重叠了。。。最后用DakerYi的方法把
image.getBackground();
改为
image.getDrawable();
经验+1
a. 用于生成连续的Gif效果图。
b. DrawableAnimation也是指此动画
帧动画实现方法很简单,完全是图片的叠加。原理和 gif 动画一样,因为每一帧过的速度太快,眼睛来不及反应所以我们觉得是动画
而且它可以任意组合动画,组合动画可以一次进行,也可以同时进行,达到了更加炫酷的效果
下面就来看看在代码中如何让使用
准备几张帧动画的图片
然后在drawable里新建xml文件 我这里加了20张图 有点长 帧动画的缺点也很明显 就是太麻烦了
oneshot:是否只播放一次 (true是播放一遍 ,false是无限轮播)
drawable:一帧引用的图片
duration:一帧播放的时间
- <?xml version="1.0" encoding="utf-8"?>
- <animation-list xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="true">
-
- <item
- android:drawable="@mipmap/push_down_1"
- android:duration="50" />
- <item
- android:drawable="@mipmap/push_down_2"
- android:duration="50" />
- <item
- android:drawable="@mipmap/push_down_3"
- android:duration="50" />
- <item
- android:drawable="@mipmap/push_down_4"
- android:duration="50" />
- <item
- android:drawable="@mipmap/push_down_5"
- android:duration="50" />
- <item
- android:drawable="@mipmap/push_down_6"
- android:duration="50" />
-
- </animation-list>

acticity里面的布局需要一个imageview用来放动画
- <ImageView
- android:id="@+id/frame_image"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:src="@mipmap/push_down_1" />
开始播放的方法
- //开始
- public void startFrame(ImageView frame_image) {
- frame_image.setBackgroundResource(R.drawable.anim_frame);
- AnimationDrawable anim = (AnimationDrawable) frame_image.getDrawable();//如果图片在mipmap里就用getBackground()方法,不然会报空
- anim.start();
- }
停止的方法
- //停止
- public void stopFrame(ImageView frame_image) {
- AnimationDrawable anim = (AnimationDrawable) frame_image.getDrawable();
- if (anim.isRunning()) { //如果正在运行,就停止
- anim.stop();
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。