我正在尝试用 gif 制作一个 recyclerview。一切都完美显示,但 fresco 不缓存 gif。向下滚动回收器并再次向上滚动后,gif 将再次加载。我认为它们应该被缓存并更快地加载。以前我使用过ION library。加载速度更快,没有缓存问题。我不得不更改 lib,因为它在 gif 解码方面存在一些问题,在此处进行了描述。当前的解决方案如下所示:
//for default initial in application class
Fresco.initialize(this);
//I have also tried to change DiskCacheConfig and ImagePipelineConfig params.
//Without any positive result
//for recyclerview on onBindViewHolder
GenericDraweeHierarchy hierarchy = holder.draweeView.getHierarchy();
Uri uri = Uri.parse(path);
hierarchy.setPlaceholderImage(R.drawable.img_bg);
Logger.e(check(uri) + " " + uri.toString());
DraweeController controller = Fresco.newDraweeControllerBuilder().setUri(uri)
.setAutoPlayAnimations(true).build();
holder.draweeView.setController(controller);
//for method which show cached uri images in imagepipeline
public static boolean check(Uri uri) {
ImagePipeline imagePipeline = Fresco.getImagePipeline();
return imagePipeline.isInBitmapMemoryCache(uri);
}
//... all the time log shows "false + gif url"
我没有看到任何关于不缓存动画图像的信息。有关于不支持的动画图像后处理的信息,但这就是全部。如何正确缓存 GIF?
编辑: 它看起来像壁画缓存动画,因为下面的方法为重新加载的 gif 返回 true。
public static boolean isImageDownloaded(Uri loadUri) {
if (loadUri == null) {
return false;
}
CacheKey cacheKey = DefaultCacheKeyFactory.getInstance()
.getEncodedCacheKey(ImageRequest.fromUri(loadUri));
return ImagePipelineFactory.getInstance().getMainDiskStorageCache().hasKey(cacheKey)
|| ImagePipelineFactory.getInstance().getSmallImageDiskStorageCache()
.hasKey(cacheKey);
}