我正在使用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
内运行,但是它可以正确运行:
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
中运行。
submit
来启动它开始加载。 - android developer