android play gif,Play.gif image in android without using webview
问题
I tried like this, which i found on the net to play gif images:
private class MYGIFView extends View {
Movie movie;
InputStream is = null;
long moviestart;
public MYGIFView(Context context) {
super(context);
// Provide your own gif animation file
is = context.getResources().openRawResource(R.drawable.mygif);
movie = Movie.decodeStream(is);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.WHITE);
super.onDraw(canvas);
long now = android.os.SystemClock.uptimeMillis();
System.out.println("now=" + now);
if (moviestart == 0) { // first time
moviestart = now;
}
System.out.println("\tmoviestart=" + moviestart);
int relTime = (int) ((now - moviestart) % movie.duration());
System.out.println("time=" + relTime + "\treltime="
+ movie.duration());
movie.setTime(relTime);
movie.draw(canvas, this.getWidth() / 2 - 20,
this.getHeight() / 2 - 40);
this.invalidate();
}
Though many have said that they got their desired result.
I have put the gif image in drawable.
I am getting movie.duration() null.
Please suggest where am i wrong or if is there any way.
回答1:
Android cannot play GIF files without WebView. You must break it apart into frames and animate it yourself.
I found on another StackOverflow post this bit of software from XoyoSoft, called GifSplitter, that can split a GIF into frames. You would then want to use AnimationDrawable to combine those.
It would look something like this:
// Your files:
res\drawable-xxxx\frame1.jpg
res\drawable-xxxx\frame2.jpg
res\drawable-xxxx\frame3.jpg
// ...
res\drawable-xxxx\frame99.jpg
Then, there is an example in the AnimationDrawable documentation above that will show how to display those images.
Lastly, you must load and play the animation; that, too, is detailed in the AnimationDrawable documentation.
来源:https://stackoverflow.com/questions/11806320/play-gif-image-in-android-without-using-webview
android play gif,Play.gif image in android without using webview相关推荐
- Android监听左右滑删除通知,Android 滑动监听RecyclerView线性流+左右划删除+上下移动...
废话不多说了,直接给大家贴代码了.具体代码如下所示: xmlns:tools="http://schemas.android.com/tools" android:layout_w ...
- ios android安全性分析,Android与iOS的对比分析及Android安全技术的设计与实现
摘要: 近年来科技的发展和进步极大的推动了智能手机的飞速发展,手机功能的日益强大使人们对其依赖度显著上升.作为与人们生活密不可分通讯工具,手机安全的重要性不言而喻.现如今,随着手机网络的迅猛发展和形形 ...
- android wear无法启用,android-wear – 无法创建Android虚拟设备,“没有为此目标安装系统映像”...
为了创建一个Android穿戴式模拟器,你需要按照下面的说明, 1.如果您的Android SDK工具版本低于22.6,您必须更新 2.在Android 4.4.2下,选择Android Wear A ...
- android 监听物理返回键,Android应用开发之react-native 监听Android物理返回键
本文将带你了解Android应用开发之react-native 监听Android物理返回键,希望本文对大家学Android有所帮助. 1. componentWillMount(){ ...
- android中仿qq最新版抽屉,Android实现3种侧滑效果(仿qq侧滑、抽屉侧滑、普通侧滑)...
自己实现了一下侧滑的三种方式(注释都写代码里了) 本文Demo下载地址:Andriod侧滑 本文实现所需框架:nineoldandroids下载地址:nineoldandroids 1.普通侧滑: 主 ...
- android 固定底部导航,如何设置android底部导航栏位置固定在android
请帮我设置底部导航栏位置固定在底部, ,因为我在输入editText字段时遇到问题,底部导航栏向上移动并覆盖其他领域如何设置android底部导航栏位置固定在android 代码: xmlns:and ...
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序 在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity, ...
- Android多个权限多次请求,android – 获取W / Activity:一次只能请求一组权限
我制作了一个应用程序,它有摄像头和GPS的请求,但是当我执行时,我会多次收到此警告,而不到1秒. W/Activity: Can reqeust only one set of permissions ...
- android 启动白屏_为什么说Android 架构的未来是 MVVM?
据<第45次中国互联网络发展状况统计报告>,2019年市场上监测到的APP数量比2018年减少85万款- 这两年,很多朋友都会有这样的疑惑: "现在Android的坑还值不值得入 ...
- Android开发实战三之导入现有Android工程项目
选择Create project from existing sample 打开Eclipse环境后,在左上方的菜单上选择[File->New->Project],会弹出[New Proj ...
最新文章
- python property内建函数的介绍
- 开源圆桌 QA 集锦
- 【ujson】pip安装ujson报错: error:Microsoft Visual C++ 14.0 is required
- Windows平台自动登录telnet批处理文件
- 操作系统知识点_内存管理
- linux c mysql 增删改查_Linux C语言连接MySQL 增删改查操作
- WP7之LongListSelector控件
- IIS 500 错误解决
- Error: could not open `C:\Program Files\Java\jre6\lib\i386\jvm.cfg')
- MySQL 主键、索引创建
- CISP 和 NISP差别一览
- Qt 常用类 (11)—— QLabel
- 微信小程序 audio 音频 组件
- SAP中内部订单实际成本和承诺行项目参考交易/业务事务标识汇总
- 高仿知乎Android客户端欢迎引导动画
- 解析域名,获得公网地址
- 数字功放-耐福NTP功放芯片详细性能概述
- insmod 加载模块过程、modprobe 与 insmod的区别 、lsmod命令
- JAVA我的世界给op_我的世界OP指令有哪些 OP权限怎么设置
- Ubuntu中使用vi编辑时方向键乱码或退格键不能使用解决方法
热门文章
- UDP sendto和recvfrom使用详解
- 服务器中有两个R文件夹,一台服务器中配置多个git sshkey
- 串口MSComm控件五种不同校验方式对数据收发的影响
- 少儿编程100讲轻松学python(九)-python如何判断字符串是否为整数
- python可以用来编写计算机网络程序吗_计算机网络(基于python做的笔记 )
- mybatisplus 结果_SpringBoot + MyBatisPlus 快速入门
- java怎么生成字母_java自动生成字母
- 多线程写mysql数据库_多线程读写mysql数据库
- html5 多页面共享数据库,可以跨页面使用HTML5 Web SQL数据库吗?(Can HTML5 Web SQL databases be used across pages?)...
- JS如何禁止别人查看网站源码