Glide listener doesn't work

半城伤御伤魂 提交于 2019-11-28 11:52:34

It seems to be a bug with ImageView's visibility if it's invisible or gone. I opened an issue here: https://github.com/bumptech/glide/issues/618

Here's one way to do it:

        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()

Ran into same issue. Having onResourceReady return false did the trick for me.

Ran into same issue ,because the width and height of my ImageView were 0,0. Gave my ImageView a default width and Height this solved my issue.

Mehdi Yari

You just need to change the return of onResourceReady and onLoadFailed from true to false.

It works for me on glide 4.9.1.

if you look at RequestListener comments you should understand.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!