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学习的兴趣,同时也能加深对制造电影的一些了解,

最新文章

  1. HTML插入FLASH
  2. 利用Abot爬虫和visjs 呈现漫威宇宙
  3. pyqt2_官网教程
  4. position之absolute与relative 详解
  5. HDU 4453:Looploop(Splay各种操作)
  6. 我的window平台下的软件
  7. 浅谈 PHP 变量可用字符
  8. MVC4新功能...压缩和合并js文件和样式文件
  9. 前端基于easyui的mvc扩展(续)
  10. vue监听滚动事件,实现滚动监听
  11. 让EditPlus支持SQL高亮提示
  12. Java 集合系列(一)
  13. 使用npm私有服务器保存公司内部强业务类型组件(三):关于业务性组件的一点思考
  14. Redis讲解以及测试要点
  15. IOS UINavigationController 更改返回按钮
  16. Easy to use cross-platform 3D engines
  17. python 基础3 函数
  18. 真核生物基因结构 &amp; mRNA结构
  19. oracle中获取执行计划
  20. Mypwd 的解读与实现 20155202

热门文章

  1. 4、mybatis动态sql+struts2(通配符+全局配置+分页)
  2. openwrt的uboot环境变量分析
  3. 如何使用自定义消息?--ESFramework 4.0 快速上手(04)
  4. [ An Ac a Day ^_^ ] CodeForces 659D Bicycle Race 计算几何 叉积
  5. Chapter 15_2 编写模块的基本方法
  6. Round Numbers(组合数学)
  7. 关于oracle数据库(8)查询2
  8. insertAdjacentHTML方法详解
  9. swift UILable的用法
  10. Android中的Glide加载图片