简体   繁体   中英

How to Lazy Load image using Glide android studio?

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM