Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

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 的问题