Android简单逐帧动画Frame的实现(二)
Android简单逐帧动画Frame的实现
1、逐帧动画
即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影。
2、实现步骤:
1、
在工程里面导入要播放的图片。此简单例子中为start_icon1,2,3.
2、
在工程res文件目录下新建一个anim文件夹,在里面新建一个start_animation.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/start_icon1" android:duration="1000" />
<item android:drawable="@drawable/start_icon2" android:duration="500" />
<item android:drawable="@drawable/start_icon3" android:duration="600" />
</animation-list>
注:此蓝色部分依次显示的图片,存放在drawable-mdpi文件下,一般1秒钟播放24张图片(帧)就感觉播放流畅了,即duration为40左右,默认单位为毫秒。
3、布局文件:
布局文件中添加一ImageView控件,用来播放动画图片。具体布局如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="开始" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="结束" />
<ImageView
android:id="@+id/image"
android:background="@anim/start_animation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
4、代码部分:
public class TestActivity extends Activity
{
AnimationDrawable anim;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.start_screen);
ImageView image = (ImageView) findViewById(R.id.image);
// image.setBackgroundResource(R.anim.start_animation);
anim = (AnimationDrawable) image.getBackground();
Button start = (Button) findViewById(R.id.button1);
Button stop = (Button) findViewById(R.id.button2);
start.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.start();
}
});
stop.setOnClickListener(new OnClickListener()
{
public void onClick(View arg0)
{
anim.stop();
}
});
}
}
注:第三四步中的紫色部分,只要选择一个就可以,两个都写显得累赘,主要功能是指定播放的资源图片。
小结:这种应用在实际应用中应该不会用到,对于初学着来说,拿着玩下还是蛮有意思的,不仅增强了对Android学习的兴趣,同时也能加深对制造电影的一些了解,
Android简单逐帧动画Frame的实现(二)的更多相关文章
- Android简单逐帧动画Frame的实现(三)
android之动画(三)通过AnimationDrawable控制逐帧动画 android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- Android 学习之逐帧动画(Frame)
帧动画就是将一些列图片.依次播放. 利用肉眼的"视觉暂留"的原理,给用户的感觉是动画的错觉,逐帧动画的原理和早期的电影原理是一样的. a:须要定义逐帧动画,能够通过代码定义.也能够 ...
- Android中实现一个简单的逐帧动画(附代码下载)
场景 Android中的逐帧动画,就是由连续的一张张照片组成的动画. 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 ...
- Android 逐帧动画isRunning 一直返回true的问题
AnimationDrawabl主要通过xml实现逐帧动画,SDK实例如下: An AnimationDrawable defined in XML consists of a single < ...
- Android 逐帧动画
原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...
- Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)
1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...
- Android 逐帧动画( Drawable 动画),这一篇就够了
前言 作为 Android 最常见的两种动画形式,逐帧动画( Drawable 动画),有着极其广泛的应用,它的原理与早起的电影以及 GIF 类似,就是把一张的图,按顺序快速切换,这样一来看上去就好像 ...
- Android中的动画详解系列【1】——逐帧动画
逐帧动画其实很简单,下面我们来看一个例子: <?xml version="1.0" encoding="utf-8"?> <animation ...
随机推荐
- hdu 1072 广搜
路径是可以重复走的,但是如果再一次走过时间重置点是没有意义的 #include <iostream> #include <cstdio> #include <cstrin ...
- pthread_create线程创建的过程剖析(转)
概述 在Linux环境下,pthread库提供的pthread_create()API函数,用于创建一个线程.线程创建失败时,它可能会返回ENOMEM或EAGAIN.这篇文章主要讨论线程创建过程中碰到 ...
- Nimbus<三>Storm源码分析--Nimbus启动过程
Nimbus server, 首先从启动命令开始, 同样是使用storm命令"storm nimbus”来启动看下源码, 此处和上面client不同, jvmtype="-serv ...
- 第三次冲刺spring会议(第四次会议)
[例会时间]2014/5/23 21:15 [例会地点]9#446 [例会形式]轮流发言 [例会主持]马翔 [例会记录]兰梦 小组成员:兰梦 ,马翔,李金吉,赵天,胡佳奇
- lucene 索引创建步骤
一.步骤: 1.存储位置:1)文件: Directory dir= FSDirectory.open(new File("D:\\LuceneIndex")); 2)内存: new ...
- CSS传统布局之布局模型
刚开始准备这篇文章的时候,查到的有很多包含“布局模型”的中文博客或是资料,但是google上并未找到类似字眼,google到的是“flex layout module”“grid layout mod ...
- bootstraptable表格基本
function tableint(){ $("#tableFromData").bootstrapTable({ url:BASE_URL+"/do/fron ...
- jenkins 中集成JNI的坑
有包名1.生成class> javac myjni\HelloJNI.java2.生成.h文件> javah -d include myini.HelloJNI3.生成.dll文件> ...
- vmware 安装提示the msi failed
原因是卸载不干净,使用批处理bat文件卸载,然后重启即可. VMware workstation 10.0序列号:MA491-6NL5Q-AZAM0-ZH0N2-AAJ5A 百度云文件:http:// ...
- <context:annotation-config> 和 <context:component-scan>的区别
转自:GOOD spring <context:annotation-config> 跟 <context:component-scan>诠释及区别 <context:a ...