Android中显示gif图片
2016-03-24 09:41
387 查看
引入xml文件布局文件中
public class MyGifView extends View { private long movieStart; private Movie movie; // 此处必须重写该构造方法 public MyGifView(Context context, AttributeSet attributeSet) { super(context, attributeSet); // 以文件流(InputStream)读取进gif图片资源 movie = Movie.decodeStream(getResources().openRawResource(R.drawable.logo_gif)); } @Override protected void onDraw(Canvas canvas) { long curTime = android.os.SystemClock.uptimeMillis(); // 第一次播放 if (movieStart == 0) { movieStart = curTime; } if (movie != null) { int duraction = movie.duration(); int relTime = (int) ((curTime - movieStart) % duraction); movie.setTime(relTime); movie.draw(canvas, 0, 0); // 强制重绘 invalidate(); } super.onDraw(canvas); } }
相关文章推荐
- android上传文件到服务器
- android studio 断开与SVN连接的 一种方法
- Android自定义View基础篇(三)之SwitchButton开关
- Android ASimpleCache缓存框架 获取缓存大小
- android之Widget开发详解
- android:windowSoftInputMode属性
- Android打Path的方法
- 【转】android程序编译过程
- VisionMobile:2015年Android使用的全球趋势(五)Android演进导致更少解锁
- android 解决华为系列手机调试时不能打印Logcat日志信息
- android创建隐藏文件或者文件夹
- Android源码编译
- [Android] 图像各种处理系列文章合集
- Android Studio开发调试Installation failed since the device possibly has stale dexed jars
- Android自定义View的使用
- Android Service完全解析,关于服务你所需知道的一切(上)
- Android Service完全解析,关于服务你所需知道的一切(下)-进程间通信
- 2015年Android开发技术小结
- 五步搞定Android开发环境部署——非常详细的Android开发环境搭建教程
- android实现zip解压