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 ...
随机推荐
- openwrt 中procd
https://wiki.openwrt.org/doc/techref/procd Procd:Openwrt的进程管理守护进程(process management daemon),它与初始化脚本 ...
- 离线消息如何实现?-- ESFramework 4.0 快速上手(02)
在ESFramework 4.0 快速上手一文中,主要介绍了如何使用ESPlus.Rapid命名空间中的引擎来快速地构建基于TCP的网络通信系统,即使是使用ESPlus.Rapid来进行ESFrame ...
- webapi中的Route的标签的命名参数name的使用
Route Names In Web API, every route has a name. Route names are useful for generating links, so that ...
- LeetCode OJ 63. Unique Paths II
Follow up for "Unique Paths": Now consider if some obstacles are added to the grids. How m ...
- 使用observable数组(Working with observable arrays)
observable数组(observable arrays) 如果你要探测和响应一个对象的变化,你应该用observables.如果你需要探测和响应一个集合对象的变化,你应该用observableA ...
- echarts图表里遇到的问题
1. 取消echarts的默认动画 : series:[{ animation:false }] 2. 控制散点图里散点的大小: series:[{ symbolSize:5 }] 3. 去除内部网格 ...
- codeforce Gym 101102A Coins (01背包变形)
01背包变形,注意dp过程的时候就需要取膜,否则会出错. 代码如下: #include<iostream> #include<cstdio> #include<cstri ...
- ios 基础数据类型
1:NSString http://blog.csdn.net/likendsl/article/details/7417878 http://xys289187120.blog.51cto.com/ ...
- mahout与nosql的两幅经典图形
- java线程数据交换Exchanger
两个线程都等到交换函数才能完成交换数据操作,代码如下: package threadLock; import java.util.Random; import java.util.concurrent ...