第一步:先上图片素材,以下素材放到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. 单尺度二维离散小波分解dwt2

    clc,clear all,close all; load woman; [cA,cH,cV,cD]=dwt2(X,'haar');%单尺度二维离散小波分解.分解小波函数haar figure,ims ...

  2. luci-bwc

    文件位于:   ../feeds/luci/modules/admin-full/src/luci-bwc.c 功能: Very simple bandwidth collector cache fo ...

  3. 与malloc有关的问题

    nefu 1026 申请动态空间存放字符串,将其排序后输出 http://acm.nefu.edu.cn/JudgeOnline/problemShow.php?problem_id=1026 #in ...

  4. C++对象模型笔记之程序设计模型

    C++程序设计模型支持三种程序设计模型 1.程序模型(procedural model) 可以理解为过程化模型,就像C一样 2.抽象数据类型模型(ADT) 数据结构教材里有说过,查了下资料也不是很明确 ...

  5. spring容器启动的加载过程(一)

    使用spring,我们在web.xml都会配置ContextLoaderListener <listener> <listener-class> org.springframe ...

  6. java的string.split()分割特殊字符时注意点

    [1]单个符号作为分隔符         String address="上海|上海市|闵行区|吴中路";      String[] splitAddress=address.s ...

  7. ajax的项目实操(只用于记录部分文件未引入)

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...

  8. C#整理 条件语句

    条件语句主要分为if else语句和switch case语句. if else语句主要分为四种格式: 1. if(表达式) {} 2.二选一 if(表达式) {} else {} 3.多选一 if( ...

  9. JavaScript(10)——Ajax以及跨域处理

    Ajax以及跨域处理 哈哈哈,终于写到最后一章了.不过也还没有结束,说,不要为了学习而学习,恩.我是为了好好学习而学习呀.哈哈哈.正在尝试爱上代码,虽然有一丢丢的难,不过,我相信我会的! [Ajax] ...

  10. 【第一篇】Python基础

    Python学习 学习站点:https://www.shiyanlou.com/ 1 hello world code如下: $ python [15:50:40] Python2.7.6(defau ...