我正在使用 Glide 加载图像,并添加了一个监听器以了解资源何时准备好或是否存在任何类型的错误:
Glide.with(mContext)
.load(url)
.placeholder(R.drawable.glide_placeholder)
// use dontAnimate and not crossFade to avoid a bug with custom views
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
// do something
return true;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
// do something
return true;
}
})
.into(mCustomImageView);
该应用程序永远不会在 onResourceReady
或 onException
内运行,但如果我删除监听器并让异步下载没有回调,它会正常运行:
Glide.with(mContext)
.load(url)
.placeholder(R.drawable.glide_placeholder)
// use dontAnimate and not crossFade to avoid a bug with custom views
.dontAnimate()
.diskCacheStrategy(DiskCacheStrategy.ALL)
.into(mCustomImageView);
我也尝试使用 GlideDrawableImageViewTarget
而不是监听器来接收回调,但应用程序在 onLoadStarted
内部运行,但从未在 onLoadCleared
、onLoadFailed 内部运行
和 onResourceReady
.
最佳答案
如果 ImageView 不可见或消失,这似乎是一个错误。我在这里打开了一个问题:https://github.com/bumptech/glide/issues/618
关于android - Glide 监听器不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32503327/