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的实现(二)的更多相关文章

  1. Android简单逐帧动画Frame的实现(三)

    android之动画(三)通过AnimationDrawable控制逐帧动画     android与逐帧动画: 效果图: 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的状态. ...

  2. Android动画效果之Frame Animation(逐帧动画)

    前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...

  3. Android 学习之逐帧动画(Frame)

    帧动画就是将一些列图片.依次播放. 利用肉眼的"视觉暂留"的原理,给用户的感觉是动画的错觉,逐帧动画的原理和早期的电影原理是一样的. a:须要定义逐帧动画,能够通过代码定义.也能够 ...

  4. Android中实现一个简单的逐帧动画(附代码下载)

    场景 Android中的逐帧动画,就是由连续的一张张照片组成的动画. 效果 注: 博客: https://blog.csdn.net/badao_liumang_qizhi 关注公众号 霸道的程序猿 ...

  5. Android 逐帧动画isRunning 一直返回true的问题

    AnimationDrawabl主要通过xml实现逐帧动画,SDK实例如下: An AnimationDrawable defined in XML consists of a single < ...

  6. Android 逐帧动画

    原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...

  7. Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)

    1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...

  8. Android 逐帧动画( Drawable 动画),这一篇就够了

    前言 作为 Android 最常见的两种动画形式,逐帧动画( Drawable 动画),有着极其广泛的应用,它的原理与早起的电影以及 GIF 类似,就是把一张的图,按顺序快速切换,这样一来看上去就好像 ...

  9. Android中的动画详解系列【1】——逐帧动画

    逐帧动画其实很简单,下面我们来看一个例子: <?xml version="1.0" encoding="utf-8"?> <animation ...

随机推荐

  1. 2、使用Struts2实现登录功能(没有连接数据)

    1.创建如下的目录结构 2.在com.entity包下创建 package com.entity; /** * 用户类 * @author Holly老师 * */ public class User ...

  2. 如何判断网页中引入jquery

    直接上代码,不信自己测. <html xmlns="http://www.w3.org/1999/xhtml"><meta http-equiv="Co ...

  3. Android 安装镜像

    1. 关机 2. 按住音量减键和电源键,直到进入fastboot模式 3. 连接上PC 4. PC端输入sudo fastboot devices验证已识别到设备 5. PC端输入sudo fastb ...

  4. 【转】Storm并行度详解

    1.Storm并行度相关的概念 Storm集群有很多节点,按照类型分为nimbus(主节点).supervisor(从节点),在conf/storm.yaml中配置了一个supervisor,有多个槽 ...

  5. vultr vps注册和后台教程

    我用了一年多vultr vps,感觉相当满意.我算是vultr最早的一批用户了,当时他们充值多少赠送多少,吸引大批新用户搬家到vultr,给linode和digitalocean vps不少的市场压力 ...

  6. 使用InternetReadFile时要注意读取完整数据

    使用这个api读取数据后,即使数据不完整,该函数不会报任何错,GetLastError也显示操作成功.使用时要注意通过其参数判断是否读取完毕 void InternetReadFileEx(HINTE ...

  7. 201312月CCF-2,ISBN号码分析

    明天要考CCF啦,偶还是很紧张的.最近看了数据结构,今天才开始上机练习,对,我就是这么懒..废话不多说,我写这篇文章主要是分析CCF编程的小窍门,因为在网上没找到,所以我决定自力更生丰衣足食.!!!! ...

  8. sql语句的group by与having子句

    准备数据: DROP TABLE IF EXISTS `t_player`; CREATE TABLE `t_player` ( `player_id` int(11) NOT NULL AUTO_I ...

  9. over 分析函数之 lag() lead()

    /*语法*/ lag(exp_str,offset,defval) over()  取前 Lead(exp_str,offset,defval) over()  取后 --exp_str要取的列 -- ...

  10. HDU - 1045 Fire Net(搜索)

    Description Suppose that we have a square city with straight streets. A map of a city is a square bo ...