-1

I want to lazy load image inside my cardview but it's not working below is my code but i am confused how to lazy load image using glide

        int width = metrics.widthPixels;
        int height = metrics.heightPixels;
        BitmapRequestBuilder builder =
                Glide.with(context)
                        .load(Constants.IMAGE_DOWNLOAD + pathName)
                        .asBitmap();
        FutureTarget futureTarget = builder.into(width, height);
        return (Bitmap) futureTarget.get();
    }

    private Bitmap loadImageForNoti(Context context, String pathName) throws ExecutionException, InterruptedException {
        DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
        int width = metrics.widthPixels;
        int height = metrics.heightPixels;
        BitmapRequestBuilder builder =
                Glide.with(context)
                        .load(pathName)
                        .asBitmap();
        FutureTarget futureTarget = builder.into(width, height);
        return (Bitmap) futureTarget.get();
    }```
[This is my [code][1] 1 ][1]


[This is my [second][2] code ][2]

i am confused where to add code to lazy load image using glide


  [1]: https://i.stack.imgur.com/851dp.png
  [2]: https://i.stack.imgur.com/CHnJQ.png
  • Does this answer your question? [How to lazy load images in ListView in Android](https://stackoverflow.com/questions/541966/how-to-lazy-load-images-in-listview-in-android) – Lunatic Jun 10 '22 at 16:16

1 Answers1

0

Use the transition effect to load the image smoothly and fast.

GlideApp  
.with(context)
.load(url)
.transition(DrawableTransitionOptions.withCrossFade()) //for loading image smoothly and fastly.
.placeholder(placeHolderUrl)
.error(errorImageUrl)
.fitCenter()
.into(imageView);

want more animation and smooth loading of images. See here https://bumptech.github.io/glide/doc/transitions.html

Let me know if you have any problem

M DEV
  • 763
  • 1
  • 7
  • 20
  • Basically the problem is that when i am opening the app and click on any image then related to that images are showing below in cardview but when i am using mobile data it's loading only half images of cardview and other images are not loaded so how to load remaining images in above code. – suraj gaikwad Jun 12 '22 at 05:43
  • @surajgaikwad you have to mention this problem in your question and also want to share images and code of that issue. Please mention this issue and code in your question. – M DEV Jun 12 '22 at 10:16