【问题标题】:Slow loading of Images using Glide on RecyclerView在 RecyclerView 上使用 Glide 缓慢加载图像
【发布时间】:2019-10-18 12:58:05
【问题描述】:

我有一个带有网格布局的 recyclerView,一次在屏幕上显示 6 张卡片,调用带有 10 个对象的 JSON,对于图像加载,我正在使用 glide

现在图像加载不符合标记 所以我搜索了更多关于 Glide 并找到了调用缩略图的方法

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

但仍然没有太大帮助

然后我使用另一种调用RequestBuilder的方法 它确实有帮助,但不是理想的水平

谁能建议我还能做些什么来减少图像的加载时间以改善用户体验?

【问题讨论】:

  • 在使用该图像后使用图像压缩代码来压缩图像,这可能有助于在更短的时间内加载图像。
  • 希望对您有所帮助:stackoverflow.com/a/39674379

标签: android android-recyclerview android-glide android-gridlayout


【解决方案1】:

使用这些选项(在 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函数。

这是滑翔所能做的最好的事情。如果它仍然需要时间而不是从服务器端压缩图像。

【讨论】:

    猜你喜欢
    • 2020-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多