Android 逐帧动画
原理:
逐帧动画是最简单的一种动画。原理就是把几张图片连续显示出来,以达到动画的效果。就相当于下面这种手绘翻页动画啦~

实现:
1、需要建立一个animation-list来设置静态图片资源、持续时间和是否循环播放。在res下建立一个anim文件夹,然后新建一个intro5.xml文件
<?xml version="1.0" encoding="utf-8"?>
<!-- 指定动画循环播放 -->
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false">
<!-- 添加多个帧 -->
<item android:drawable="@drawable/intro5" android:duration="400" />
<item android:drawable="@drawable/intro51" android:duration="400" /> </animation-list>
android:drawable="@drawable/intro5"是图片资源
android:duration="400"指的是这幅图片显示400毫秒
android:oneshot="false"表示循环播放
2、把动画资源intro5.xml设置到ImageView的背景图里面,以便AnimationDrawable的调用
<ImageView
android:id="@+id/anim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@anim/intro5"
android:scaleType="center"
/>
在android:background="@anim/intro5"的地方设置第一步写的动画资源。当然,如果你想连续播放多个动画的话,可以写好几个动画资源,然后在java代码里不断设置ImageView的背景。
3、需要AnimationDrawable来控制逐帧动画的开始、结束等其他操作。
public class MainActivity extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button play = (Button)findViewById(R.id.play);
Button stop = (Button)findViewById(R.id.stop);
ImageView imageView = (ImageView)findViewById(R.id.anim);
//获取AnimationDrawable动画对象
final AnimationDrawable anim = (AnimationDrawable)imageView
.getBackground();
play.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//开始播放动画
anim.start();
}
});
stop.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
//停止播放动画
anim.stop();
}
});
}
}
AnimationDrawable除去开始播放动画和停止播放动画外还有一些操作,不过个人觉得几乎是用不上。
不过还是附上官网的链接吧:http://developer.android.com/guide/topics/graphics/drawable-animation.html
Android 逐帧动画的更多相关文章
- Android 逐帧动画isRunning 一直返回true的问题
AnimationDrawabl主要通过xml实现逐帧动画,SDK实例如下: An AnimationDrawable defined in XML consists of a single < ...
- Android 逐帧动画( Drawable 动画),这一篇就够了
前言 作为 Android 最常见的两种动画形式,逐帧动画( Drawable 动画),有着极其广泛的应用,它的原理与早起的电影以及 GIF 类似,就是把一张的图,按顺序快速切换,这样一来看上去就好像 ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- Android中的动画具体解释系列【1】——逐帧动画
逐帧动画事实上非常easy,以下我们来看一个样例: <?xml version="1.0" encoding="utf-8"?> <anima ...
- Android简单逐帧动画Frame的实现(三)
android之动画(三)通过AnimationDrawable控制逐帧动画 android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...
- Android简单逐帧动画Frame的实现(二)
Android简单逐帧动画Frame的实现 Android简单逐帧动画Frame的实现 1.逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影. 2.实现步骤: 1. 在工程里 ...
- 转Android 用Animation-list实现逐帧动画
Android 用Animation-list实现逐帧动画 第一步:先上图片素材,以下素材放到res/drawable目录下: http://blog.csdn.net/aminfo/arti ...
- Android动画之逐帧动画(FrameAnimation)详解
今天我们就来学习逐帧动画,废话少说直接上效果图如下: 帧动画的实现方式有两种: 一.在res/drawable文件夹下新建animation-list的XML实现帧动画 1.首先在res/drawab ...
- Android 学习之逐帧动画(Frame)
帧动画就是将一些列图片.依次播放. 利用肉眼的"视觉暂留"的原理,给用户的感觉是动画的错觉,逐帧动画的原理和早期的电影原理是一样的. a:须要定义逐帧动画,能够通过代码定义.也能够 ...
随机推荐
- uploadfile图片上传和ashx
uploadify.swf需要是支持中文 $(function () { //获取所有上传按钮id $("div[id^='fileInput_']").each(fu ...
- Execel(导出新方法):
#region 新方法 //var sbHtml = new StringBuilder(); //sbHtml.Append("<table border='1' cellspaci ...
- oracle表大小
查某一用户下的表 select SEGMENT_NAME,TABLESPACE_NAME,sum(BYTES/1024/1024)||'M' from USER_extents where SEGM ...
- shell -vim
编辑文件 vim vim 1.txt 点击i进入编辑模式 如果发现按上下左右有问题的且出现乱码的话,可能是编码格式不对导致的,在crt或者是xshell设置一下编码格式就行. 保存是点击ecs先退到预 ...
- oracle 常用函数【转】
常用Oracle函数 SQL中的单记录函数 1.ASCII 返回与指定的字符对应的十进制数; SQL> select ascii('A') A,ascii('a') a,ascii('0') z ...
- "undefined method `root' for nil:NilClass" error when using "pod install" 解决办法
如果pod undate 的时候报错"undefined method `root' for nil:NilClass" error when using "pod in ...
- 关于JSTL一些需要说明的
一直认为与.NET相比,JAVA最大的问题在于不统一,当然这可能是自由的代价,正如某某某一样,造成的结果是需要记各种各样的版本,有jsp的.servlet的.各种框架的.各种容器的,不一而足.今天要说 ...
- ReactiveX编程范式
ReactiveX http://reactivex.io/ An API for asynchronous programmingwith observable streams The Observ ...
- http缓存之304 last-modified,cache-control:max-age,Etag等
因最近客户端慢的问题,系统分析了下http协议缓存问题.本文主要记录总结http缓存相关知识. 1. 讨论涉及的要点 访问返回类 > 访问返回200 OK > 访问返回200 (from ...
- linux centos service 参数详解
Service文件 开门见山,直接来看两个实际的服务配置文件吧. 第一个配置是 CoreOS 系统中 Docker 服务的 Unit 文件,路径是 /usr/lib/systemd/system/do ...