Android显示GIF动画完整示例(二)
MainActivity如下:
package cc.testgif2; import android.os.Bundle;
import android.app.Activity;
/**
* Demo描述:
* 利用自定义View控件显示GIF动画
* 详细代码参见GIFView
*
* 参考资料:
* http://blog.csdn.net/dawanganban/article/details/9816083
* Thank you very much
*/
public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
GIFView如下:
package cc.testgif2; import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Movie;
import android.util.AttributeSet;
import android.view.View; public class GIFView extends View {
private Movie mMovie;
private long startTime;
private int gifDuration;
private boolean isBeginPlay=true;
public GIFView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
} public GIFView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
} public GIFView(Context context) {
super(context);
init();
} private void init(){
mMovie = Movie.decodeStream(getResources().openRawResource(R.drawable.gif));
gifDuration= mMovie.duration();
} @Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// 从开机到现在的毫秒(不包括手机睡眠的时间在内)
long currrentTime = android.os.SystemClock.uptimeMillis();
// 第一次播放
if (isBeginPlay) {
startTime = currrentTime;
isBeginPlay = false;
} int playTime = (int) ((currrentTime - startTime) % gifDuration);
mMovie.setTime(playTime);
mMovie.draw(canvas, 0, 0);
// 重绘
invalidate();
} }
main.xml如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
> <TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world"
android:layout_centerHorizontal="true"/> <cc.testgif2.GIFView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
/> </RelativeLayout>
Android显示GIF动画完整示例(二)的更多相关文章
- Android显示GIF动画完整示例(一)
MainActivity如下: package cc.testgif; import com.ant.liao.GifView; import com.ant.liao.GifView.GifImag ...
- Android显示GIF动画 GifView
android中显示gif动画原生态一般支持的不是很好,故找了一个开源的项目,现简单介绍如下: GifView 是一个为了解决android中现在没有直接显示gif的view,只能通过mediapla ...
- Android中的AlertDialog使用示例二(普通选项对话框)
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,AlertDialog实现方法为建造者模式. ...
- Android显示GIF动画(转载)
GifView 是一个为了解决android中现在没有直接显示gif的view,只能通过mediaplay来显示这个问题的项目,其用法和 ImageView一样,支持gif图片 使用方法: 1-把Gi ...
- Android开源项目:GifView——Android显示GIF动画
下载:http://code.google.com/p/gifview/downloads/list 简介:android中现在没有直接显示gif的view,只能通过mediaplay来显示,且还常常 ...
- Android窗口管理服务WindowManagerService显示窗口动画的原理分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8611754 在前一文中,我们分析了Activi ...
- Android之Animation动画各属性的参数意思(二)
现在就来讲讲Animation里这四个标签的属性. 一.这四个标签alpha.scale.translate.rotate共有的属性为: android:duration 动画持续时间, ...
- 【Android】21.4 图片动画缩放示例
分类:C#.Android.VS2015: 创建日期:2016-03-21 一.简介 该例子演示如何动画缩放图片,实现类似"点击看大图"的效果. 二.示例 1.运行截图 2. ...
- Android BLE与终端通信(二)——Android Bluetooth基础科普以及搜索蓝牙设备显示列表
Android BLE与终端通信(二)--Android Bluetooth基础搜索蓝牙设备显示列表 摘要 第一篇算是个热身,这一片开始来写些硬菜了,这篇就是实际和蓝牙打交道了,所以要用到真机调试哟, ...
随机推荐
- java中如何计算两个时间段的月份差
直接计算,先取得两个日期的年份和月份,月份差=(第二年份-第一年份)*12 + 第二月份-第一月份
- TabelView的多选模式
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource> @property(nonatomic,st ...
- 使得fiddler来抓包查看微信浏览器的网页源码
需要工具:http://www.telerik.com/fiddler 下载安装后 第二步: 打开这个选项: 设置代理:allow remote computer to connect 端口为888 ...
- .net mvc Authorization Filter,Exception Filter与Action Filter
一:知识点部分 权限是做网页经常要涉及到的一个知识点,在使用MVC做权限设计时需要先了解以下知识: MVC中Url的执行是按照Controller->Action->View页面,但是我们 ...
- Delphi 类型转换函数(有几个函数没见过,FloatToStrF,FloatToText等等)
Chr 将一个有序数据转换为一个ANSI字符 Ord 将一个有序类型值转换为它的序号 Round 转换一个实型值为四舍五入后的整型值 Trunc 转换一个实型值为小数截断后的整型值 Int 返回浮点数 ...
- 通过自定义window来实现提示框效果
#import <UIKit/UIKit.h>#import <Foundation/Foundation.h> @interface ZMStatuBarHud : NSOb ...
- hdu5188 加限制的01背包问题
http://acm.hdu.edu.cn/showproblem.php? pid=5188 Problem Description As one of the most powerful brus ...
- android编译系统的makefile文件Android.mk写法如下
(1)Android.mk文件首先需要指定LOCAL_PATH变量,用于查找源文件.由于一般情况下Android.mk和需要编译的源文件在同一目录下,所以定义成如下形式:LOCAL_PATH:=$(c ...
- 工具篇-MAT(Memory Analyzer Tool)
--- layout: post title: 工具篇-MAT(Memory Analyzer Tool) description: 让内存泄漏无所遁形 2015-10-08 category: bl ...
- C# Best Practices - Specify Clear Method Parameters
Improve parameters parameter order public OperationResult PlaceOrder(Product product, int quantity, ...