使用 glide 在 recyclerview imageview 项上加载图像。 impelemented glide 监听器我意识到图像资源已准备就绪,但图像未显示在 imageview 中。当我在 glide 监听器 onResourceRady 中添加 imageview.setDrawable(resource) 时,图像会显示,但正常情况下不会显示,这是我的代码,我感谢任何帮助。
GlideApp
.with(this.myContext)
.load(item.add)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(
e: GlideException?,
model: Any?,
target: Target<Drawable>?,
isFirstResource: Boolean
): Boolean {
myContext.toast("error:\n ${e?.causes}")
return true
}
override fun onResourceReady(
resource: Drawable?,
model: Any?,
target: Target<Drawable>?,
dataSource: DataSource?,
isFirstResource: Boolean
): Boolean {
myContext.toast("resource ready")
//holder.img.setImageDrawable(资源) 返回真 } }) .error(R.drawable.neterror) .into(holder.img) }
最佳答案
Glide 取决于 RequestListener
的 onResourceReady
方法返回的 bool 值,如果返回值为 true
(这是你的情况)意味着监听器已处理在目标上设置资源。要允许 Glide 更新目标的请求,请返回 false
。
有关更多信息,请查看文档:https://bumptech.github.io/glide/doc/debugging.html#requestlistener-and-custom-logs
关于android Glide 资源已准备好但图像未显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64335054/