Android只播放gif动画
使用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
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- 根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
- 根标签下,通过item标签对动画中的每一个图片进行声明
- android:duration 表示展示所用的该图片的时间长度
- -->
- <animation-list
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="true"
- >
- <item android:drawable="@drawable/icon1" android:duration="150"></item>
- <item android:drawable="@drawable/icon2" android:duration="150"></item>
- <item android:drawable="@drawable/icon3" android:duration="150"></item>
- <item android:drawable="@drawable/icon4" android:duration="150"></item>
- <item android:drawable="@drawable/icon5" android:duration="150"></item>
- <item android:drawable="@drawable/icon6" android:duration="150"></item>
- </animation-list>
倒序显示动画文件:animation2.xml
- <?xml version="1.0" encoding="utf-8"?>
- <!--
- 根标签为animation-list,其中oneshot代表着是否只展示一遍,设置为false会不停的循环播放动画
- 根标签下,通过item标签对动画中的每一个图片进行声明
- android:duration 表示展示所用的该图片的时间长度
- -->
- <animation-list
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:oneshot="true"
- >
- <item android:drawable="@drawable/icon6" android:duration="150"></item>
- <item android:drawable="@drawable/icon5" android:duration="150"></item>
- <item android:drawable="@drawable/icon4" android:duration="150"></item>
- <item android:drawable="@drawable/icon3" android:duration="150"></item>
- <item android:drawable="@drawable/icon2" android:duration="150"></item>
- <item android:drawable="@drawable/icon1" android:duration="150"></item>
- </animation-list>
第三步:上布局文件,放在res/layout目录下,文件名main.xml:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:orientation="vertical">
- <ImageView android:id="@+id/animationIV"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5px"
- android:src="@drawable/animation1"/>
- <Button android:id="@+id/buttonA"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5px"
- android:text="顺序显示" />
- <Button android:id="@+id/buttonB"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5px"
- android:text="停止" />
- <Button android:id="@+id/buttonC"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:padding="5px"
- android:text="倒序显示" />
- </LinearLayout>
第四步:上Activity文件,文件名:MainActivity.java
- package org.shuxiang.test;
- import android.app.Activity;
- import android.graphics.drawable.AnimationDrawable;
- import android.os.Bundle;
- import android.view.View;
- import android.view.View.OnClickListener;
- import android.view.Window;
- import android.widget.Button;
- import android.widget.ImageView;
- public class Activity10 extends Activity
- {
- private ImageView animationIV;
- private Button buttonA, buttonB, buttonC;
- private AnimationDrawable animationDrawable;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- requestWindowFeature(Window.FEATURE_NO_TITLE);
- setContentView(R.layout.test10);
- animationIV = (ImageView) findViewById(R.id.animationIV);
- buttonA = (Button) findViewById(R.id.buttonA);
- buttonB = (Button) findViewById(R.id.buttonB);
- buttonC = (Button) findViewById(R.id.buttonC);
- buttonA.setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- animationIV.setImageResource(R.drawable.animation1);
- animationDrawable = (AnimationDrawable) animationIV.getDrawable();
- animationDrawable.start();
- }
- });
- buttonB.setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- animationDrawable = (AnimationDrawable) animationIV.getDrawable();
- animationDrawable.stop();
- }
- });
- buttonC.setOnClickListener(new OnClickListener()
- {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- animationIV.setImageResource(R.drawable.animation2);
- animationDrawable = (AnimationDrawable) animationIV.getDrawable();
- animationDrawable.start();
- }
- });
- }
- }
Android只播放gif动画的更多相关文章
- Android实现播放GIF动画的强大ImageView
我个人是比较喜欢逛贴吧的,贴吧里总是会有很多搞笑的动态图片,经常看一看就会感觉欢乐很多,可以释放掉不少平时的压力.确实,比起一张单调的图片,动态图片明显更加的有意思.一般动态图片都是GIF格式的,浏览 ...
- android 拓展ImageView播放GIF动画
原生Android控件ImageView并不能支持播放GiF格式的图片.如果将一张GIF的图片放入ImageView中,它只会显示图片的第一帧,不会产生任何动画效果. Android中播放GIF动画实 ...
- android 通过帧动画方式播放Gif动画
注意:经过本人测试,这个方法很耗内存, 图片一多就崩了.慎用 <1>用工具(photoshop或者FireWorks)将GIF动画图片分解成多个GIF静态图片,然后保存在res\drawa ...
- Android播放gif动画,增加屏幕掉金币效果
前言:播放gif的版本有很多,我这边使用Android自带的Movie类播放gif动画,也是在别人的基础上进行修改.有同样需求的朋友可以参考我的demo. 1.效果图如下: 2.部分主要代码 Main ...
- Android高级控件(二)——SurfaceView实现GIF动画架包,播放GIF动画,自己实现功能的初体现
Android高级控件(二)--SurfaceView实现GIF动画架包,播放GIF动画,自己实现功能的初体现 写这个的原因呢,也是因为项目中用到了gif动画,虽然网上有很多的架包可以实现,不过我们还 ...
- Android 播放Gif 动画
在Android 中是不支持直接使用Gif 图片关联播放帧动画,如下动画在Android 中是无法播放的: Android 提供了另外一种解决的办法,就是使用AnimationDrawable 这一函 ...
- Android播放图片动画
1.布局文件中添加ImageView <ImageView android:id="@+id/iv_fan" android:layout_width="wrap_ ...
- Android View的滑动 动画
[scrollTo/scrollBy] //控件内的文字会移动,但是控件本身不会移动,而且移动到控件之外之后,文字也就看不见了 if(v.equals(button2)){ button2.scrol ...
- Android(java)学习笔记264:Android下的属性动画高级用法(Property Animation)
1. 大家好,在上一篇文章当中,我们学习了Android属性动画的基本用法,当然也是最常用的一些用法,这些用法足以覆盖我们平时大多情况下的动画需求了.但是,正如上篇文章当中所说到的,属性动画对补间动画 ...
随机推荐
- Hive分区和桶的概念
Hive 已是目前业界最为通用.廉价的构建大数据时代数据仓库的解决方案了,虽然也有 Impala 等后起之秀,但目前从功能.稳定性等方面来说,Hive 的地位尚不可撼动. 其实这篇博文主要是想聊聊 S ...
- 【Java】 Scanner类的几个方法
通过 Scanner 类可以获取用户的输入,创建 Scanner 对象的基本语法如下: Scanner sc = new Scanner(System.in); nextInt().next()和ne ...
- Dubbo内核实现之SPI简单介绍
这个部分单独写一页,看起来更高大上一些. 1.概括 Dubbo采用微内核+插件体系,使得设计优雅,扩展性强.那所谓的微内核+插件体系是如何实现的呢! 即我们定义了服务接口标准,让厂商去实现(如果不了解 ...
- FPGA+ARM or FPGA+DSP?
网上有人说.现在的FPGA,ARM功能已经强大到无需DSP协助处理了,未来DSP会不会消声灭迹?是DSP取代FPGA和ARM,还是ARM,FPGA取代DSP呢?担心好不容易学精了DSP,结果DSP变成 ...
- jupyter notebook 小技巧
Converting notebooks to other formats¶ !pip install https://github.com/ipython-contrib/jupyter_contr ...
- gp数据库运维
最近需要将一份db2导出的历史数据入库gp集群,然后把每天的增量数据导出成txt文件和对应的log日志,再ftp传输给另外一台机器.其中陆续碰到一些坑,在此记录 历史文件数据清洗 列分隔符的选择 碰到 ...
- bzoj——2127: happiness
2127: happiness Time Limit: 51 Sec Memory Limit: 259 MBSubmit: 2570 Solved: 1242[Submit][Status][D ...
- 1015 Reversible Primes (20)(20 point(s))
problem A reversible prime in any number system is a prime whose "reverse" in that number ...
- [ 原创 ] git使用技巧
Git的使用--如何将本地项目上传到Github Git分支图介绍 https://www.cnblogs.com/cheneasternsun/p/5952830.html https://www. ...
- 机器学习之路:python 多项式特征生成PolynomialFeatures 欠拟合与过拟合
分享一下 线性回归中 欠拟合 和 过拟合 是怎么回事~为了解决欠拟合的情 经常要提高线性的次数建立模型拟合曲线, 次数过高会导致过拟合,次数不够会欠拟合.再建立高次函数时候,要利用多项式特征生成器 生 ...





