[在RecyclerView上使用Glide在Android上缓慢加载图像

问题描述 投票:0回答:1

我有一个带有网格布局的recyclerView,一次在屏幕上显示6张卡,并调用包含10个对象的JSON,并且为了加载图像,我正在使用滑行

现在图像加载未达到标记要求因此,我搜索了更多有关Glide的内容,并找到了调用缩略图的方法

Glide
     .with(Context)
     .load(url)
     .thumbnail(0.25f)
     .transition(DrawableTransitionOptions.withCrossFade())
     .into(ImageView);

但是仍然没有太大帮助

然后我使用另一种调用RequestBuilder的方法它确实有帮助,但没有达到期望的水平

有人可以建议我做些什么以减少图像的加载时间以使用户体验更好吗?

android android-recyclerview android-glide android-gridlayout
1个回答
0
投票

使用这些选项(在Kotlin中-)>

GlideApp.with(mContext)
                .apply(getRectangleRequestOptions(true))
                .load(url)
                .thumbnail(0.5f)
                .into(layout.bannerAdapterImg)

getSquareRequestOptions是-

fun getSquareRequestOptions(isCenterCrop:Boolean=true): RequestOptions {
        return RequestOptions().also {
            it.placeholder(R.drawable.ic_placeholder)
            it.error(R.drawable.ic_err_image)
            it.override(200, 200)                         // override size as you need
            it.diskCacheStrategy(DiskCacheStrategy.ALL)   //If your images are always same
            it.format(DecodeFormat.PREFER_RGB_565)        // the decode format - this will not use alpha at all

            if(isCenterCrop)
                it.centerCrop()
            else
                it.fitCenter()
        }
    }

*对于Java代码,只需更新Java中的getSquareRequestOptions函数。

这是最好的滑行方法。如果仍然需要时间,那么可以从服务器端压缩图像。

© www.soinside.com 2019 - 2024. All rights reserved.