简体   繁体   English

如何使用 Glide android 工作室延迟加载图像?

[英]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我想在我的 cardview 中延迟加载图像,但它不起作用下面是我的代码,但我很困惑如何使用 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.使用transition效果可以流畅快速地加载图像。

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.想要更多 animation 和顺利加载图像。 See here https://bumptech.github.io/glide/doc/transitions.html看这里https://bumptech.github.io/glide/doc/transitions.html

Let me know if you have any problem如果您有任何问题,请告诉我

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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