Android 加载GIF图最佳实践方案

Github:https://github.com/koral–/android-gif-drawable

添加依赖:

implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.18'

直接把布局文件中的 ImageView 替换为 GifImageView

<pl.droidsonroids.gif.GifImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@mipmap/appblog"
    />

代码使用:

GifImageView gifImageView = (GifImageView) findViewById(R.id.gifImageView);
GifDrawable gifDrawable = (GifDrawable) gifImageView.getDrawable();

根据需要调用以下方法即可,效果还不错,很流畅

gifDrawable.start();  //开始播放
gifDrawable.stop();  //停止播放
gifDrawable.reset();  //复位,重新开始播放
gifDrawable.isRunning();  //是否正在播放
gifDrawable.setLoopCount( 2 );  //设置播放的次数,播放完了就自动停止
gifDrawable.getCurrentLoop(); //获取正在播放的次数
gifDrawable.getCurrentPosition;  //获取现在到从开始播放所经历的时间
gifDrawable.getDuration();  //获取播放一次所需要的时间

总结:尝试用Glide 实现,但是效果不是不好,卡顿,然后发现依赖这个jar后,效果不错,且jar也不是很大,也就75k

上一篇 Android解决CPU休眠Timer不执行
下一篇 Glide加载图片时,报You must not call setTag() on a view Glide is targeting 的问题
目录
文章列表
1 Dubbo 与 Spring Cloud 完美结合
Dubbo 与 Spring Cloud 完美结合
2
MySQL传参字段与DB字段数据类型不一致导致精度问题采坑记录
MySQL传参字段与DB字段数据类型不一致导致精度问题采坑记录
3
Windows下安装OpenSSH
Windows下安装OpenSSH
4
Android获取签名文件或apk的MD5及SHA1
Android获取签名文件或apk的MD5及SHA1
5
微信小程序开发经验总结
微信小程序开发经验总结
最新评论
一位WordPress评论者
一位WordPress评论者
2月12日
您好,这是一条评论。若需要审核、编辑或删除评论,请访问仪表盘的评论界面。评论者头像来自 Gravatar。