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?
Glide allows users to specify three different placeholders that are used under different circumstances: placeholder. error.
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.
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 ().
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.
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.
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?
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.
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 you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With