我有一个RecyclerViewAdapter,在onBindViewHolder中,我通过AsyncTask调用从Google下载所需的图像。
RecyclerViewAdapter中有一些项需要相同的图像。我试图通过只下载本地文件存储中不存在的映像来处理这个问题;否则,它就使用已经下载的映像。
现在发生的情况是,如果RecyclerView中有多个项在足够多的时间内调用相同的图像,那么ImageView中的一个项将为空白/白色,但其余的项将正确显示图像。
我本来希望能够捕获这个场景,只使用Thread.sleep,然后再次尝试获取/使用该文件,但是我没有抛出任何异常或任何东西,所以我甚至不知道如何捕获该场景来处理它。
我在logcat中看到的唯一一件看起来很有帮助的事情是:
D/skia: --- Failed to create image decoder with message 'unimplemented'
然而,它并不是抛出异常,而是将其记录为一条消息。
然而,它确实指出图像的解码存在一个问题。所以我检查了BitmapFactory.decodeFile文档,它说,如果它不能解码它,它会返回一个null。所以我试着在解码后检查我的位图是否为null,但是它从未命中if语句,这意味着它永远不会返回null,所以我不知道该怎么做。
new Getlogos(holder.logoImageView.getTag().toString(), holder.itemView.getContext(), new Getlogos.AsyncResponse() {
@Override
public void returnBitmapURI(String URI, String tag) {
if (holder.logoImageView != null && holder.logoImageView.getTag().toString().equals(tag)) {
if (URI.contains("drawable://")) {
int id = Integer.parseInt(URI.substring(11));
Bitmap myBitmap = BitmapFactory.decodeResource(context.getResources(), id);
holder.logoImageView.setImageBitmap(myBitmap);
} else {
Bitmap myBitmap = BitmapFactory.decodeFile(URI);
holder.logoImageView.setImageBitmap(myBitmap);
}
}
}
}).execute();这个问题有时只会发生,而且在相同的图像上也不会一致发生。通常情况下,有相同映像可供下载/使用的项目之间会有所不同。有时根本不发生。
有人能说明那个skia信息来自哪里,以及当它无法解码时我如何捕捉它,这样我就能处理它了吗?
发布于 2018-11-21 10:34:10
用幻灯片在recyclerView中显示图像 将此依赖项添加到build.gradle
implementation 'com.github.bumptech.glide:glide:4.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.8.0'Inside
请求选项显示错误图像、占位符图像等。CircularProgressDrawable表示占位符可绘制(可选)
val circularProgressDrawable = CircularProgressDrawable(mContext)
circularProgressDrawable.strokeWidth = 5f
circularProgressDrawable.centerRadius = 30f
circularProgressDrawable.start()
val requestOption : RequestOptions = RequestOptions()
.placeholder(circularProgressDrawable)
.error(R.drawable.ic_error_1)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.priority(Priority.HIGH)
.dontAnimate()
.dontTransform()初始化幻灯片如下所示
Glide.with(mContext)
.load(model.imageUrl)
.apply(requestOption)
.into(holder.imageView!!)发布于 2019-09-02 09:46:05
如果是这样的话:
未能创建带有“未实现”消息的图像解码器
您可以通过判断“位图==空”来捕获异常吗?如下代码所示:

我的英语不是很好,我希望你能理解我说的话!
https://stackoverflow.com/questions/53409693
复制相似问题