滑翔监听器不起作用

Glide listener doesn#39;t work(滑翔监听器不起作用)

本文介绍了滑翔监听器不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Glide 加载图像,并添加了一个侦听器以了解资源何时准备好或是否存在任何类型的错误:

I'm using Glide to load images and I added a listener to know when resource is ready or if there was an error of any type:

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

该应用程序永远不会在 onResourceReadyonException 内运行,但如果我删除监听器并让异步下载没有回调,它会正常运行:

The app never runs inside onResourceReady or onException but if I remove the listener and let the async download without a callback, it runs correctly:

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 内部运行,但从未在 onLoadClearedonLoadFailed 内部运行onResourceReady.

I tried also with GlideDrawableImageViewTarget instead of listener to receive callbacks but app runs inside onLoadStarted but never runs inside onLoadCleared, onLoadFailed and onResourceReady.

推荐答案

如果 ImageView 不可见或消失,这似乎是一个 bug.我在这里打开了一个问题:https://github.com/bumptech/glide/issues/618

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

这篇关于滑翔监听器不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:滑翔监听器不起作用

基础教程推荐