How to set OkHttpClient for glide

since glide 4.0.0 it has changed a little bit. first of all GlideModule is deprecated and you need to use AppGlideModule if you are developing an application and LibraryGlideModule for library development. you need to use @GlideModule above your custom AppGlideModule class. secondly there is no register() method in Glide object any more. and finally … Read more

Set Background Image to Relative Layout using Glide in Android

You can load an image in a RelativeLayout like this. I’m just showing you the hard part which is setting an image to the background. For Glide version before 4.X Glide.with(this).load(imageViewPath).asBitmap().into(new SimpleTarget<Bitmap>(relLayoutWidth, relLayoutHeight) { @Override public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) { Drawable drawable = new BitmapDrawable(context.getResources(), resource); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { … Read more

Recyclerview Adapter and Glide – same image every 4-5 rows

The answers here are incorrect, although they’re on the right track. You need to call Glide#clear(), not just set the image drawable to null. If you don’t call clear(), an async load completing out of order may still cause view recycling issues. Your code should look like this: @Override public void onBindViewHolder(ViewHolder holder, int position) … Read more

Error “You must not call setTag() on a view Glide is targeting” when use Glide

The key is ViewTarget.setTagId; setting it will free up the default setTag on the ImageView so you can use it as root in the item layout. It was introduced in Glide 3.6.0 in issue #370. In your manifest add this: <application android:name=”.App” Then create an application context class: public class App extends Application { @Override … Read more

Preload multiple images with Glide

Use the following code to cache images without displaying them using the downloadOnly method if you are looking to download images from the web and store them in the diskCache: FutureTarget<File> future = Glide.with(applicationContext) .load(yourUrl) .downloadOnly(500, 500); using preload method if you want to load them into the Memory Cache. Glide.with(context) .load(url) .preload(500, 500); You … Read more