Gio*_*oli 35 android callback imageview android-glide
我正在使用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);
Run Code Online (Sandbox Code Playgroud)
该应用程序永远不会在内部运行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);
Run Code Online (Sandbox Code Playgroud)
我也尝试使用GlideDrawableImageViewTarget而不是监听器来接收回调但是应用程序在内部运行onLoadStarted但从未在内部运行onLoadCleared,onLoadFailed并且onResourceReady.
Gio*_*oli 31
如果ImageView的可见性不见或消失,它似乎是一个错误.我在这里打开了一个问题:https://github.com/bumptech/glide/issues/618
and*_*per 15
这是一种方法:
Glide.with(context).load(...)
.listener(object : RequestListener<Drawable> {
override fun onLoadFailed(e: GlideException?, model: Any?, target: Target<Drawable>?, isFirstResource: Boolean): Boolean {
//TODO handle error images while loading photo
return true
}
override fun onResourceReady(resource: Drawable?, model: Any?, target: Target<Drawable>?, dataSource: DataSource?, isFirstResource: Boolean): Boolean {
//TODO use "resource" as the photo for your ImageView
return true
}
}).submit()
Run Code Online (Sandbox Code Playgroud)
小智 8
您只需要将onResourceReady和的返回值onLoadFailed从 true更改为 false。
它对我有用glide 4.9.1。
如果您查看 RequestListener 评论,您应该明白。
遇到了同样的问题,因为我的宽度和高度ImageView分别为0,0(两者layout_width并layout_height分别设置为wrap_content无图像设定于ImageView最初)。给出ImageView默认宽度和高度解决了我的问题。
| 归档时间: |
|
| 查看次数: |
33676 次 |
| 最近记录: |