转自http://blog.csdn.net/jwzhangjie/article/details/18323101
分类: android 视频播放器制作2014-01-15 21:39 3315人阅读 评论(0) 收藏 举报

在处理耗时工作的时候,大多数会弹出一个加载的框,里面有一个连续旋转的图片,很多时候都是用一张图片,使用rotate来设定旋转,不过看起来不太美观,没有形象感,在3.0之前Android有两种动画效果分别是补间动画和帧动画,用一张图片实现的是使用补间动画,定义给出两个关键帧,通过一些算法将给定属性值在给定的时间内在两个关键帧间渐变。我个人比较倾向的是帧动画,不过这个需要美工的支持,还有一种方式就是通过反编译其他的软件获取图片,我不是美工也没有美工的支持,所以就解压QQ的apk,获取它里面的显示加载动画的图片,图片资源http://download.csdn.net/download/jwzhangjie/6852981。

看看如何实现的

load_animation_1.xml

[html] view plaincopy
  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="false"
  10. >
  11. <item android:drawable="@drawable/qb_tenpay_loading_1" android:duration="150"></item>
  12. <item android:drawable="@drawable/qb_tenpay_loading_2" android:duration="150"></item>
  13. <item android:drawable="@drawable/qb_tenpay_loading_3" android:duration="150"></item>
  14. <item android:drawable="@drawable/qb_tenpay_loading_4" android:duration="150"></item>
  15. <item android:drawable="@drawable/qb_tenpay_loading_5" android:duration="150"></item>
  16. <item android:drawable="@drawable/qb_tenpay_loading_6" android:duration="150"></item>
  17. <item android:drawable="@drawable/qb_tenpay_loading_7" android:duration="150"></item>
  18. <item android:drawable="@drawable/qb_tenpay_loading_8" android:duration="150"></item>
  19. <item android:drawable="@drawable/qb_tenpay_loading_9" android:duration="150"></item>
  20. <item android:drawable="@drawable/qb_tenpay_loading_10" android:duration="150"></item>
  21. <item android:drawable="@drawable/qb_tenpay_loading_11" android:duration="150"></item>
  22. <item android:drawable="@drawable/qb_tenpay_loading_12" android:duration="150"></item>
  23. </animation-list>

load_animation_2.xml

[html] view plaincopy
  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="false"
  10. >
  11. <item android:drawable="@drawable/common_loading_0" android:duration="150"></item>
  12. <item android:drawable="@drawable/common_loading_1" android:duration="150"></item>
  13. <item android:drawable="@drawable/common_loading_2" android:duration="150"></item>
  14. <item android:drawable="@drawable/common_loading_3" android:duration="150"></item>
  15. <item android:drawable="@drawable/common_loading_4" android:duration="150"></item>
  16. <item android:drawable="@drawable/common_loading_5" android:duration="150"></item>
  17. <item android:drawable="@drawable/common_loading_6" android:duration="150"></item>
  18. <item android:drawable="@drawable/common_loading_7" android:duration="150"></item>
  19. <item android:drawable="@drawable/common_loading_8" android:duration="150"></item>
  20. <item android:drawable="@drawable/common_loading_9" android:duration="150"></item>
  21. <item android:drawable="@drawable/common_loading_10" android:duration="150"></item>
  22. <item android:drawable="@drawable/common_loading_11" android:duration="150"></item>
  23. </animation-list>

wifi_animation_1.xml

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <animation-list
  3. xmlns:android="http://schemas.android.com/apk/res/android"
  4. android:oneshot="false"
  5. >
  6. <item android:drawable="@drawable/wifi_1" android:duration="150"></item>
  7. <item android:drawable="@drawable/wifi_2" android:duration="150"></item>
  8. <item android:drawable="@drawable/wifi_3" android:duration="150"></item>
  9. <item android:drawable="@drawable/wifi_4" android:duration="150"></item>
  10. <item android:drawable="@drawable/wifi_5" android:duration="150"></item>
  11. <item android:drawable="@drawable/wifi_6" android:duration="150"></item>
  12. </animation-list>

布局文件:

[html] view plaincopy
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3. android:layout_width="match_parent"
  4. android:layout_height="match_parent"
  5. android:orientation="vertical" >
  6. <Button
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:text="动画加载1"
  10. android:id="@android:id/button1"
  11. ></Button>
  12. <Button
  13. android:id="@android:id/button2"
  14. android:layout_width="wrap_content"
  15. android:layout_height="wrap_content"
  16. android:layout_toRightOf="@android:id/button1"
  17. android:layout_marginLeft="20dip"
  18. android:text="动画加载2"
  19. />
  20. <Button
  21. android:id="@android:id/button3"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:layout_toRightOf="@android:id/button2"
  25. android:layout_marginLeft="20dip"
  26. android:text="动画wifi1"
  27. />
  28. <ImageView
  29. android:id="@+id/animationIV"
  30. android:layout_width="wrap_content"
  31. android:layout_height="wrap_content"
  32. android:layout_centerInParent="true"
  33. android:contentDescription="@string/app_name"
  34. />
  35. <ImageView
  36. android:id="@+id/animationIV2"
  37. android:layout_width="wrap_content"
  38. android:layout_height="wrap_content"
  39. android:layout_toRightOf="@id/animationIV"
  40. android:src="@anim/load_animation_2"
  41. android:contentDescription="@string/app_name"
  42. android:layout_alignBottom="@id/animationIV"
  43. android:layout_marginLeft="30dip"
  44. />
  45. <ImageView
  46. android:id="@+id/animationIV3"
  47. android:layout_width="wrap_content"
  48. android:layout_height="wrap_content"
  49. android:layout_above="@id/animationIV"
  50. android:contentDescription="@string/app_name"
  51. android:layout_marginTop="20dip"
  52. />
  53. </RelativeLayout>
[java] view plaincopy
  1. public class Test extends BaseActivity{
  2. private Button button1,button2,button3;
  3. private ImageView animationIV;
  4. private ImageView animationIV2;
  5. private ImageView animationIV3;
  6. private AnimationDrawable AniDraw, AniDraw2, AniDraw3;
  7. @Override
  8. protected void onCreate(Bundle savedInstanceState) {
  9. super.onCreate(savedInstanceState);
  10. setContentView(R.layout.test);
  11. button1 = (Button)findViewById(android.R.id.button1);
  12. button1.setOnClickListener(new OnClickListener() {
  13. @Override
  14. public void onClick(View v) {
  15. if (AniDraw.isRunning()) {
  16. AniDraw.stop();
  17. }else {
  18. AniDraw.start();
  19. }
  20. }
  21. });
  22. button2 = (Button)findViewById(android.R.id.button2);
  23. button2.setOnClickListener(new OnClickListener() {
  24. @Override
  25. public void onClick(View v) {
  26. if (AniDraw2.isRunning()) {
  27. AniDraw2.stop();
  28. }else {
  29. AniDraw2.start();
  30. }
  31. }
  32. });
  33. button3 = (Button)findViewById(android.R.id.button3);
  34. button3.setOnClickListener(new OnClickListener() {
  35. @Override
  36. public void onClick(View v) {
  37. if (AniDraw3.isRunning()) {
  38. AniDraw3.stop();
  39. }else {
  40. AniDraw3.start();
  41. }
  42. }
  43. });
  44. animationIV = (ImageView)findViewById(R.id.animationIV);
  45. /**
  46. * 这里设置的是setBackgroundResource,那么你获取的时候通过getBackground
  47. */
  48. animationIV.setBackgroundResource(R.anim.load_animation_1);
  49. AniDraw = (AnimationDrawable)animationIV.getBackground();
  50. /**
  51. * 在xml里面通过src来设置跟在代码里面使用setImageResource获取的时候通过getDrawable
  52. * 例如:animationIV2.setImageResource(R.anim.load_animation_2);是一样的
  53. */
  54. animationIV2 = (ImageView)findViewById(R.id.animationIV2);
  55. AniDraw2 = (AnimationDrawable)animationIV2.getDrawable();
  56. animationIV3 = (ImageView)findViewById(R.id.animationIV3);
  57. animationIV3.setImageResource(R.anim.wifi_animation_1);
  58. AniDraw3 = (AnimationDrawable)animationIV3.getDrawable();
  59. }

转载于:https://www.cnblogs.com/Small-Life/p/4320258.html

Android逐帧动画的实现相关推荐

  1. Android 逐帧动画(Frame)

    Android 逐帧动画(Frame)  很好理解就是将多张图片放到一个容器里面通过控制这些图片一帧一张图片从而形成动画 使用的使用通过AnimationDrawable 加载放好的图片 然后通过调用 ...

  2. Android逐帧动画——让图片动起来

    Android逐帧动画--让图片动起来 前言:逐帧动画要求开发者把动画过程的每张静态图片都收集起来,然后由android来控制依次显示这些静态图片,然后利用人眼视觉暂留的原理,给用户造成"动 ...

  3. android 创建帧动画,Android 逐帧动画创建实例详解

    Android 逐帧动画创建实例详解 前言: 我们看早期电影的时候,电影通常是一张一张播放,用我们现在专有名词来说,就是一帧帧来,安卓同样有这样动画效果的编排形式. 那么我们先定义逐帧动画xml文件 ...

  4. android 逐帧动画自动播放以及逐帧动画与渐变动画结合的停止问题

    关于逐帧动画的自动播放: android 逐帧动画一般不能直接在onCreat()方法里直接调用.start(),否则只是播放动画的第一帧,可重写onWindowFocusChanged(boolea ...

  5. android语音动画,Android逐帧动画的简单使用-语音播放效果的实现

    逐帧动画(Frame-By-Frame Animation)原理很简单,即快速切换不同的图片,形成动画效果.Android中逐帧动画的实现方式也很简单,下面以语音播放效果为例说明. 1. 首先准备图片 ...

  6. Android逐帧动画和补间动画

    本篇博客来看一下Android中的逐帧动画和补间动画. 一.逐帧动画 逐帧动画也叫Drawable Animation. 在Android中实现逐帧动画,就是由设计师给出一系列状态不断变化的图片, 开 ...

  7. Android -- 逐帧动画

    在处理耗时工作的时候,大多数会弹出一个加载的框,里面有一个连续旋转的图片,很多时候都是用一张图片,使用rotate来设定旋转,不过看起来不太美观,没有形象感,在3.0之前Android有两种动画效果分 ...

  8. android 张口逐帧动画,Android中实现一个简单的逐帧动画(附代码下载)

    场景 Android中的逐帧动画,就是由连续的一张张照片组成的动画. 效果 注: 实现 首先准备一组不同表情的照片,放在res/drawable下,然后在此目录下新建动画资源文件fairy.xml 这 ...

  9. android 播放gif动画效果,android 通过帧动画方式播放Gif动画

    注意:经过本人测试,这个方法很耗内存, 图片一多就崩了.慎用 <1>用工具(photoshop或者FireWorks)将GIF动画图片分解成多个GIF静态图片,然后保存在res\drawa ...

  10. Android自定义控件:动画类---逐帧动画AnimationDrawable

    1:概述 Android动画包括View Animation(视图动画)和Property Animator(属性动画),而View Animation包括Tween Animation(补间动画)和 ...

最新文章

  1. Android 知识杂记(MVP模式)
  2. LeetCode实战:旋转链表
  3. ACMNO.2 输入一个华氏温度,要求输出摄氏温度。公式为 c=5(F-32)/9 输出要求有文字说明,取位2小数。 输入 一个华氏温度,浮点数 输出 摄氏温度,浮点两位小数
  4. Axure RP使用攻略--入门级(七)之axure元件使用思路的补充
  5. 庆祝杭州移动电视诞生一周年
  6. boost::first_scalar的测试程序
  7. docker的镜像创建与Dockefile的编写
  8. 万字长文 - 解读功能开关 | IDCF
  9. linux安装软件包(pip, distribute, nose, virtualenv)
  10. testNG之组测试
  11. 6-4 二叉树的非递归遍历 (25分)_本周小结!(二叉树)
  12. 面试题9:斐波那契数列
  13. Kotlin入门(3)基本变量类型的用法
  14. AutoCAD.net(一):更改AutoCAD窗口的标题和图标
  15. python截图识别文字_python截图并转换文字
  16. idea和搜狗输入法快捷键冲突_Win10 输入法简繁体快捷键与 IDEA 冲突
  17. 智能优化算法:斑点鬣狗优化算法-附代码
  18. 如何从0到1打磨一门 Elasticsearch 线上直播课?
  19. 1.4.3 ASBR-Summary-LSA
  20. Unity3D消耗CPU过高解决办法

热门文章

  1. GO语言开发天天生鲜项目第四天 商品后台管理
  2. [项目管理] ISO900X 标准体系
  3. im即时通讯源码/uniapp即时通讯im源码附视频安装教程
  4. python excel图表 导出word模板_使用python将Excel数据填充Word模板并生成Word
  5. 计算机实验excel总结,EXCEL实验报告
  6. python清洗数据去除停用词_python去除停用词(结巴分词下)
  7. 手把手教你如何下载编译Spring源码
  8. staruml顺序图转通信图_【航图详解】ICAO机场图!
  9. 2.4GHz频段天线的选择
  10. 公司用的非标普通自动化用单片机还是plc_高级电气自动化工程师必备十大技能...