Glide不会在ViewHolder中加载所有图像

时间:2017-01-03 19:57:47

标签: android android-glide

所以我有一个带有自定义适配器的RecyclerView,我使用Glide从URL下载图像(如果适用)。这里的相关代码段:

        @Override
        public void onBindViewHolder(ViewHolder holder, int position) {
            final Location location = mLocations.get(position);

            holder.title.setText(location.getTitle());

            if (location.hasImage()) {
                String imageUrl = NetworkHelper.getImageUrl(getContext(),location.getImageName());

                holder.image.setVisibility(View.VISIBLE);
                // Use Glide for image loading
                Glide.with(getContext())
                        .load(imageUrl)
                        .diskCacheStrategy(DiskCacheStrategy.ALL)
                        .centerCrop()
                        .into(new GlideDrawableImageViewTarget(holder.image) {
                            @Override
                            public void onLoadFailed(Exception e, Drawable errorDrawable) {
                            super.onLoadFailed(e, errorDrawable);
                            e.printStackTrace();
                        }
                            @Override
                            public void onResourceReady(GlideDrawable resource, GlideAnimation<? super GlideDrawable> animation) {
                                super.onResourceReady(resource, animation);
                            }
                        });
            } else {
                // Due to the nature of the RecyclerView, we need to ensure we clear
                // out images to odd behavior.
                Glide.clear(holder.image);
                holder.image.setVisibility(View.GONE);
            }

        }

问题是onResourceReady()方法并不总是被调用,因此并非所有图像都被加载。我已经验证了所有传递的URL,它们看起来都很好。这里是否存在Glide特定问题?如果我将一个未加载的URL并将其硬编码到imageUrl变量中,它仍然没有被下载,那么必须有一些特定于那些导致滑行失败的图像。可能是超时问题?

编辑:我添加了onLoadFailed方法,它确实命中了,但是Exception为null,这有点奇怪。基本上与此处描述的问题相同:https://github.com/bumptech/glide/issues/741

0 个答案:

没有答案