第一步:先上图片素材,以下素材放到res/drawable目录下:

http://blog.csdn.net/aminfo/article/details/7847761

图片素材:

文件名称:

icon1.png

icon2.png

icon3.png

icon4.png

icon5.png

icon6.png

第二步:上动画Animation-list帧布局文件,有2个,一个是按顺序显示动画,一个是倒序显示动画,文件存放在res/drawable目录下

顺序显示动画文件:animation1.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. 根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
  4. 根标签下,通过item标签对动画中的每一个图片进行声明
  5. android:duration 表示展示所用的该图片的时间长度
  6. -->
  7. <animation-list
  8. xmlns:android="http://schemas.android.com/apk/res/android"
  9. android:oneshot="true"
  10. >
  11. <item android:drawable="@drawable/icon1" android:duration="150"></item>
  12. <item android:drawable="@drawable/icon2" android:duration="150"></item>
  13. <item android:drawable="@drawable/icon3" android:duration="150"></item>
  14. <item android:drawable="@drawable/icon4" android:duration="150"></item>
  15. <item android:drawable="@drawable/icon5" android:duration="150"></item>
  16. <item android:drawable="@drawable/icon6" android:duration="150"></item>
  17. </animation-list>

倒序显示动画文件:animation2.xml

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <!--
  3. 根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
  4. 根标签下,通过item标签对动画中的每一个图片进行声明
  5. android:duration 表示展示所用的该图片的时间长度
  6. -->
  7. <animation-list
  8. xmlns:android="http://schemas.android.com/apk/res/android"
  9. android:oneshot="true"
  10. >
  11. <item android:drawable="@drawable/icon6" android:duration="150"></item>
  12. <item android:drawable="@drawable/icon5" android:duration="150"></item>
  13. <item android:drawable="@drawable/icon4" android:duration="150"></item>
  14. <item android:drawable="@drawable/icon3" android:duration="150"></item>
  15. <item android:drawable="@drawable/icon2" android:duration="150"></item>
  16. <item android:drawable="@drawable/icon1" android:duration="150"></item>
  17. </animation-list>

第三步:上布局文件,放在res/layout目录下,文件名main.xml:

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:orientation="vertical">
  6. <ImageView android:id="@+id/animationIV"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:padding="5px"
  10. android:src="@drawable/animation1"/>
  11. <Button android:id="@+id/buttonA"
  12. android:layout_width="wrap_content"
  13. android:layout_height="wrap_content"
  14. android:padding="5px"
  15. android:text="顺序显示" />
  16. <Button android:id="@+id/buttonB"
  17. android:layout_width="wrap_content"
  18. android:layout_height="wrap_content"
  19. android:padding="5px"
  20. android:text="停止" />
  21. <Button android:id="@+id/buttonC"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:padding="5px"
  25. android:text="倒序显示" />
  26. </LinearLayout>

第四步:上Activity文件,文件名:MainActivity.java

  1. package org.shuxiang.test;
  2. import android.app.Activity;
  3. import android.graphics.drawable.AnimationDrawable;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.view.View.OnClickListener;
  7. import android.view.Window;
  8. import android.widget.Button;
  9. import android.widget.ImageView;
  10. public class Activity10 extends Activity
  11. {
  12. private ImageView animationIV;
  13. private Button buttonA, buttonB, buttonC;
  14. private AnimationDrawable animationDrawable;
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. requestWindowFeature(Window.FEATURE_NO_TITLE);
  19. setContentView(R.layout.test10);
  20. animationIV = (ImageView) findViewById(R.id.animationIV);
  21. buttonA = (Button) findViewById(R.id.buttonA);
  22. buttonB = (Button) findViewById(R.id.buttonB);
  23. buttonC = (Button) findViewById(R.id.buttonC);
  24. buttonA.setOnClickListener(new OnClickListener()
  25. {
  26. @Override
  27. public void onClick(View v) {
  28. // TODO Auto-generated method stub
  29. animationIV.setImageResource(R.drawable.animation1);
  30. animationDrawable = (AnimationDrawable) animationIV.getDrawable();
  31. animationDrawable.start();
  32. }
  33. });
  34. buttonB.setOnClickListener(new OnClickListener()
  35. {
  36. @Override
  37. public void onClick(View v) {
  38. // TODO Auto-generated method stub
  39. animationDrawable = (AnimationDrawable) animationIV.getDrawable();
  40. animationDrawable.stop();
  41. }
  42. });
  43. buttonC.setOnClickListener(new OnClickListener()
  44. {
  45. @Override
  46. public void onClick(View v) {
  47. // TODO Auto-generated method stub
  48. animationIV.setImageResource(R.drawable.animation2);
  49. animationDrawable = (AnimationDrawable) animationIV.getDrawable();
  50. animationDrawable.start();
  51. }
  52. });
  53. }
  54. }

转Android 用Animation-list实现逐帧动画的更多相关文章

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

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

  2. 逐帧动画(Frame-by-frame Animations)

    1.这一类动画可以创建一个Drawable序列,这些Drawable可以按照指定的时间间歇一个一个的显示. xml定义方法 <animation-list xmlns:android=" ...

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

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

  4. Android笔记(六十三) android中的动画——逐帧动画( frame-by-frame animation)

    就好像演电影一样,播放实现准备好的图片,来实现动画效果. 逐帧动画需要用到AnimationDrawable类,该类主要用于创建一个逐帧动画,然后我们把这个动画设置为view的背景即可. androi ...

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

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

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

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

  7. Android 逐帧动画

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

  8. css3 animation实现逐帧动画

    css3里面的animation属性非常强大,但是自己用的比较少,最近有次面试就刚好被问到了,趁现在有时间就对animation做一个小总结.同时实现一个逐帧动画的demo作为练习 animation ...

  9. animation中的steps()逐帧动画

    在我们平时做宽高确定,需要背景图片切换的效果时,我如果用的是一张大的png图片.而且恰好是所有小图都是从左向右排列的,那么 我们只需测量出某一个小图距左侧有多少像素(x),然后我们banckgroun ...

  10. Android中的动画具体解释系列【1】——逐帧动画

    逐帧动画事实上非常easy,以下我们来看一个样例: <?xml version="1.0" encoding="utf-8"?> <anima ...

随机推荐

  1. Django中使用Bootstrap

    一.在Django中引用Bootstrap模版 1.首先下载bootsrtap代码(http://v3.bootcss.com/getting-started/#download),并将下载后的文件放 ...

  2. NGUI等比缩放

    /// <summary> /// UI 等比缩放 /// </summary> static private void AdaptiveUI() { ; ; UIRoot u ...

  3. Mozilla Firefox的各级版本链接

    Mozilla Firefox的各级版本链接 及语言 https://ftp.mozilla.org/pub/firefox/releases/

  4. 动态得到WCF的代理类并生成代码

    Uri uri = new Uri("http://localhost:6580/Service1.svc?wsdl");             MetadataExchange ...

  5. c/c++ 浮点型处理

    #include <stdio.h> #include <iostream> #include <string> #include <string.h> ...

  6. SpringMvc+thymeleaf+HTML5中文乱码问题

    SpringMvc+thymeleaf+HTML5环境下遇到中文乱码...... 按照以往经验逐个排查,开发环境统一为utf-8编码,服务器也配置了编码过滤器,tomcat也是utf-8编码.前台页面 ...

  7. How can I create an Asynchronous function in Javascript?

    哈哈:)我的codepen 的代码笔记是:http://codepen.io/shinewaker/pen/eBwPxJ --------------------------------------- ...

  8. CSSHack 兼容性

    史上最全的CSS hack方式一览    CSS hack技巧大全    Can i use CSS hack CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6-IE11,Fire ...

  9. php 分页类(3)

    <?php class Page { private $total; //总记录 private $pagesize; //每页显示多少条 private $limit; //limit pri ...

  10. APP生产流程图片解说

    尽我所能总结下一个app的生产过程,未必完整,也未必是所有的app产生的一个过程,不同公司会有很大的不同,我只是想总结下一般的大众的,做个参考. 需求策划: 设计: 开发: 测试: 发布没什么可画的了 ...