帧动画就是将一些列图片。依次播放。

利用肉眼的“视觉暂留”的原理,给用户的感觉是动画的错觉,逐帧动画的原理和早期的电影原理是一样的。

a:须要定义逐帧动画,能够通过代码定义。也能够通过XML文件定义。一般XML文件定义比較直观

<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="false"> <!--false是循环播放 -->
<!-- drawables是每一张图片。 duration是图片持续的时间 -->
<item android:drawable="@drawable/g1" android:duration="200" />
<item android:drawable="@drawable/g2" android:duration="200" />
<item android:drawable="@drawable/g3" android:duration="200" />
<item android:drawable="@drawable/g4" android:duration="200" />
<item android:drawable="@drawable/g5" android:duration="200" />
<item android:drawable="@drawable/g6" android:duration="200" />
<item android:drawable="@drawable/g7" android:duration="200" />
<item android:drawable="@drawable/g8" android:duration="200" />
<item android:drawable="@drawable/g9" android:duration="200" />
<item android:drawable="@drawable/g10" android:duration="200" />
<item android:drawable="@drawable/g11" android:duration="200" />
</animation-list>

当中oneshot代表的是否循环播放,false是循环播放,true是仅仅播放一次

b:将上述的XMLd定义的资源,设置为ImageView的背景

        //找到imageview
ImageView iv = (ImageView) findViewById(R.id.iv);
//将帧动画的资源文件设置为imageview的背景
iv.setBackgroundResource(R.drawable.frameanimation);

c:获得AnimationDrawable对象

        //获取AnimationDrawable对象
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();

d:開始播放动画就ok

    //開始播放动画
ad.start();

Activity整个代码:

public class MainActivity extends Activity {

    @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); //找到imageview
ImageView iv = (ImageView) findViewById(R.id.iv);
//将帧动画的资源文件设置为imageview的背景
iv.setBackgroundResource(R.drawable.frameanimation);
//获取AnimationDrawable对象
AnimationDrawable ad = (AnimationDrawable) iv.getBackground();
//開始播放动画
ad.start();
}
}

演示效果:

Android 学习之逐帧动画(Frame)的更多相关文章

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

    Android简单逐帧动画Frame的实现   Android简单逐帧动画Frame的实现 1.逐帧动画 即是通过播放预先排序好的图片来实现动态的画面,感觉像是放电影. 2.实现步骤: 1. 在工程里 ...

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

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

  3. Android(java)学习笔记198:Android下的逐帧动画(Drawable Animation)

    1.帧动画: 帧动画顾名思义,一帧一帧播放的动画就是帧动画. 帧动画和我们小时候看的动画片的原理是一样的,在相同区域快速切换图片给人们呈现一种视觉的假象感觉像是在播放动画,其实不过是N张图片在一帧一帧 ...

  4. Android(java)学习笔记141:Android下的逐帧动画(Drawable Animation)

    1. 帧动画: 帧动画顾名思义,一帧一帧播放的动画就是帧动画. 帧动画和我们小时候看的动画片的原理是一样的,在相同区域快速切换图片给人们呈现一种视觉的假象感觉像是在播放动画,其实不过是N张图片在一帧一 ...

  5. android中的逐帧动画

    在android中实现动画最简单的一种方式就是使用逐帧动画(AnimationDrawable).逐帧动画的原理同最古老的动画机制是一样的,通过快速的播放一组变化微小的图片,在人眼的视差时间下,达到一 ...

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

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

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

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

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

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

  9. Android动画之逐帧动画(FrameAnimation)详解

    今天我们就来学习逐帧动画,废话少说直接上效果图如下: 帧动画的实现方式有两种: 一.在res/drawable文件夹下新建animation-list的XML实现帧动画 1.首先在res/drawab ...

随机推荐

  1. PostgreSQL order by 排序问题

    默认的排序为order by 字段名, 如果该字段不允许为空的情况下可以这样操作, 但是当字段允许为null时,order by 字段名的方式会导致: 升序时(asc): 会从最小值开始升序,最后面接 ...

  2. js中的原型哲学思想

    https://segmentfault.com/a/1190000005824449 记得当年初试前端的时候,学习JavaScript过程中,原型问题一直让我疑惑许久,那时候捧着那本著名的红皮书,看 ...

  3. 装箱I(01背包)

    描述 给两个有一定容量的箱子,往里面装宝石(宝石总容量不能超过箱子容量),不同的宝石有不同的容量和价值.求两个箱子里最大宝石的价值. 输入 line 1: Input n;  n:表示宝石数量    ...

  4. Jeddict目前的使用现状

    一.为什么使用jeddict 工具:提升生产力的工具:创建并部署一个CRUD服务系统,只需要5-10分钟 规范:生成的代码,都是稳定可执行代码(前端自动使用selenium框架测试,后端使用Arqui ...

  5. 1.ABP使用boilerplate模版创建解决方案

    1.到ABP框架的官网(http://www.aspnetboilerplate.com/),自动生成一个解决方案 每步注解: 第一步:AngularJS是一款比较火的SPA(Single Page ...

  6. kb-07专题线段树-04--离散化;

    /* poj2528 线段树 好题,用到了离散化,二分定位,特殊的区间查寻方式:在下面的代码注释中有详细的解释: */ #include<iostream> #include<cst ...

  7. POJ2594Treasure Exploration(最小路径覆盖,相交)

    Treasure Exploration Have you ever read any book about treasure exploration? Have you ever see any f ...

  8. Promise简单实现--摘抄

    Promise 看了些promise的介绍,还是感觉不够深入,这个在解决异步问题上是一个很好的解决方案,所以详细看一下,顺便按照自己的思路实现一个简单的Promise. Promise/A+规范: 首 ...

  9. 【leetcode】Find All Anagrams in a String

    [leetcode]438. Find All Anagrams in a String Given a string s and a non-empty string p, find all the ...

  10. 小程序-支持的最小像素px

    经过我手机多次测试,支持的最小px为: 8px;