我正在使用 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
.