Glide not loading real image and stuck with placeholder

有些话、适合烂在心里 提交于 2019-11-30 02:40:56

try to add .dontAnimate() It caused by TransitionDrawable too and it seems so becuase after scroll there's no animation because it's cached. the correct code is

Glide.with(view.getContext()).load(url).placeholder(R.drawable.default_profile).dontAnimate().into(view);

I hope to be helpful for you

Check if you have added Internet permission in the manifest:

<uses-permission android:name="android.permission.INTERNET"/>

Glide does not fire exception if there is no Internet connectivity.

If someone comes across this in the future you may need to add

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Unsure of the exact reason for this change, nonetheless my code didn't work without that permission, and now does with it.

Use ProgressBar as loading gif

Glide.with(context).
        load(url)
        .listener(new RequestListener<String, GlideDrawable>() {
            @Override
            public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }

            @Override
            public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
                progressBar.setVisibility(View.GONE);
                return false;
            }
        })
        .crossFade(1000)
        .into(imageView);

Below is a weird fix that worked for me.

The following always fails for me (12 trials) - I never see the real image:

Glide.with(context)
 .load(url)
 .asBitmap()
 .into(new SimpleTarget<Bitmap>(iconWidth, iconHeight) { ... }

The following always succeeds for me (12 trials) - I always see the real image:

Glide.with(context)
 .load(url)
 .asBitmap()
 .listener(new RequestListener() {
    public boolean onException(Exception e,Object o,Target t,boolean b)
               {return false;}
    public boolean onResourceReady(Object o,Object p,Target t,boolean b,boolean c)  
               {return false;}})
 .into(new SimpleTarget<Bitmap>(iconWidth, iconHeight) { ... }

As you can see, the only difference here is that I added a listener. Makes little sense, but these trials were done pretty carefully, so I'm going with it.

Suvarthee Chakravarti

Dont use transition or animation for Glide.It will solve your problem

Code :

Glide.with(context)
    .load(horizontalHappyHourList.get(position).getImage())
//  .transition(DrawableTransitionOptions.withCrossFade(400)) //Optional
    .apply(RequestOptions.diskCacheStrategyOf(DiskCacheStrategy.RESOURCE)
    .error(R.drawable.no_image))
    .into(holder.imageView);
theJango

Seems strange but only thing I could guess is Your URL is valid as You already said. Your remote is getting downloaded even getting applied on your image view but your placeholder is somehow hiding it. Glide has some bugs related to placeholder stuff.

My suggestion would be to try below:

Glide.with(view.getContext()).load(url).
placeholder(R.drawable.default_profile).fitCenter().into(view);

So the trick is placeholder is set via setImageDrawable() so the ImageView will just display it as usual, but you tell Glide to use the fitCenter explicitly which will fit the loaded image nicely within the ImageView's laid out size via a Transformation and then set it via setImageDrawable(). Since the fitted image is a perfect fit, center will just draw the image covering the whole area of the view.

Give it a try.

None of the solutions above worked for me. The issue may be at the placeholder you're using. If the view you're using to load the image has a placeholder, it causes some issues. Removing that placeholder for some reason seems to fix it.

So, if the (Image)View you're trying to inflate has a placeholder, such as android:src="@mipmap/placeholder", remove it.

        <ImageView
            android:id="@+id/imgGallery"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@mipmap/rugova1" />

like this

 <ImageView
            android:id="@+id/imgGallery"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            />

It worked for me.

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