使用easygifanimator软件把gif动画打散为图片。

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

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

图片素材:

文件名称:

icon1.png

icon1.png

icon1.png

icon1.png

icon1.png

icon1.png

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

顺序显示动画文件:animation1.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="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

[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="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:

[html] view plaincopy
  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

[java] view plaincopy
  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. }

转载于:https://www.cnblogs.com/lee0oo0/p/3183463.html

Android只播放gif动画相关推荐

  1. android如何播放动画,Android中播放Gif动画取巧的办法

    由于做的项目,要有个动画的等待效果,第一时间想到的就是Gif(懒,省事),但是试了好多据说能播放Gif的控件,也写过,但是放到魅族手机上就是不能播放,所有就想了个招,既然Gif能在浏览器上播放,那an ...

  2. android中播放gif动画之二

    2019独角兽企业重金招聘Python工程师标准>>> 在上一篇,是使用代码通过构造方法传入要播放的gif动画的id进行获取的.本文进一步改造,让GifView和ImageView一 ...

  3. android中播放gif动画之一

    在android中默认的控件是不支持gif格式的图片的,只能显示图片的第一帧,这里需要借助于Movie类.将图片进行解析播放.下面使用一种纯代码的自定义控件,这种方式使用方便,但不支持像ImageVi ...

  4. android中播放gif动画之三

    之前写了些简单的类基本可以实现gif的播放,主要是使用的Movie类来解决的.今天无意中在网上看到有个开源小项目GifView可以用来解析播放GIF,名字居然跟我写的控件一样,呵呵,看了源码,实现方式 ...

  5. android svg路径动画,Android和播放SVG动画

    把你的SVG图像,并将其转换为VectorDrawable here 您下载的XML文件添加到您的项目,看看它的外观.这里有一个VectorDrawable的一个例子的旋转和路径变形动画准备: and ...

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

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

  7. android 播放gif动画效果,Android实现可播放GIF动画的ImageView

    Android的原生控件并不支持播放GIF格式的图片.我们都知道,在Android中如果想要显示一张图片,可以借助ImageView来完成,但是如果将一张GIF图片设置到ImageView里,它只会显 ...

  8. Glide加载gif动画只播放一次的方法 Glide加载gif动画先显示最后一帧再开始播放动画导致闪屏的解决方案

    场景: Android App利用ViewPager制作引导页,然后利用Glide加载gif动画. 问题: 1.Glide加载gif动画如何只播放一次? 2.Glide加载gif动画,在viewPag ...

  9. Android高级控件(二)——SurfaceView实现GIF动画架包,播放GIF动画,自己实现功能的初体现...

    Android高级控件(二)--SurfaceView实现GIF动画架包,播放GIF动画,自己实现功能的初体现 写这个的原因呢,也是因为项目中用到了gif动画,虽然网上有很多的架包可以实现,不过我们还 ...

  10. android 4.2 开机动画,android开机动画制作与播放原理简介 (适用android4-4.2,其他版本未试验)...

    代码所在位置:/frameworks/base/cmds/bootanimation,其主要包含以下三个文件 BootAnimation_main.cpp BootAnimation.h bootAn ...

最新文章

  1. Android项目中创建编译期的注解
  2. oracle 游标中抛出异常的处理方式
  3. Bert-as-Service库Embedding句子
  4. 音频录入后以不同采样率输出
  5. MFC略缩图控件实现
  6. 去除文件头部的u+feff_关于FEFF的简短故事,一个不可见的UTF-8字符破坏了我们的CSV文件
  7. Bash数组操作教程
  8. 配置tomcat6.0的HTTPS(单向)
  9. python方向键控制角色_python方向键控制上下左右代码
  10. Word文档加密技巧
  11. Waymo无人车,每天能绕地球一圈
  12. .net mvc 一个Action的 HttpGet 和 HttpPost
  13. 最后7天!阿里云2020云内存数据库峰会现场参会报名中
  14. kubernetes-kube-scheduler进程源码分析
  15. hishop6.0和易分销2.0数据库迁移手册
  16. Gradient Descent
  17. android 简单的闪屏页,闪屏页的实现简单原理
  18. JaveMail实现发送QQ邮件
  19. SecureCRT8.3+SecureCRT_keygen完成注册
  20. 战略管理:概念与案例

热门文章

  1. R 回归 虚拟变量na_R语言 | 回归分析(一)
  2. 关于AI的目标导向型行动计划
  3. 前端如何来做权限管理?
  4. 手机CPU性能天梯图及品牌
  5. 特斯拉舍命狂奔:史上最强自动驾驶芯片发布背后,一场蓄意已久的进攻
  6. 音频格式怎么转换成mp3格式?
  7. 2021-2027全球与中国陶瓷基板白板市场现状及未来发展趋势
  8. 家居物联网(IoT)接入控制与认证的再思考
  9. 一文详解GATK-HaplotypeCaller 变异检测原理和实战
  10. 华光职业学院计算机专业,关于给予张庆俊等同学省高校计算机一级 考试成绩优秀奖励的通知...