我正在使用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() {

@Override

public boolean onException(Exception e, String model, Target target, boolean isFirstResource) {

// do something

return true;

}

@Override

public boolean onResourceReady(GlideDrawable resource, String model, Target 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上.

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐