Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Glide not loading real image and stuck with placeholder

I have a pretty basic load image from server line code:

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

For some reason, I'm always stuck with the placeholder being displayed and never the real image!

I have made sure that a valid and working url is being passed. And, if I use the same code without the placeholder it works fine

Glide.with(view.getContext()).load(url).into(view); 

Any ideas why?

like image 962
TareK Khoury Avatar asked Apr 03 '16 11:04

TareK Khoury


People also ask

What is Glide placeholder?

Glide allows users to specify three different placeholders that are used under different circumstances: placeholder. error.

How do you get pictures off of Glide?

To simply load an image to LinearLayout, we call the with() method of Glide class and pass the context, then we call the load() method, which contains the URL of the image to be downloaded and finally we call the into() method to display the downloaded image on our ImageView.

How to add placeholder image to imageview in glide?

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

What are placeholders in OpenGlide?

Glide allows users to specify three different placeholders that are used under different circumstances: Placeholders are Drawables that are shown while a request is in progress. When a request completes successfully, the placeholder is replaced with the requested resource.

What happens if a model is null in glide?

By default Glide treats null urls/models as errors, so users who expect null should set a fallback Drawable. Are placeholders loaded asynchronously? No. Placeholders are loaded from Android resources on the main thread. We typically expect placeholders to be small and easily cacheable by the system resource cache.

Can you put a placeholder on a circular image?

If you’re loading circular images for example, you may want to include circular placeholder resources with your application. Alternatively you could also consider a custom View to clip your placeholder in the same manner as your Transformation. Is it ok to use the same Drawable as a placeholder in multiple Views?


2 Answers

Try to add .dontAnimate() It caused by TransitionDrawable too and it seems so because 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 it will be helpful for you.

like image 180
Abbes Yassine Avatar answered Sep 19 '22 20:09

Abbes Yassine


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.

like image 28
Ivo Stoyanov Avatar answered Sep 18 '22 20:09

Ivo Stoyanov