我在 GridView 中显示了大约 50 个带有来自服务器的 url 的图像,其中包含图像(120*120) 加载图像花费太多时间。平均原始图像大小约为 50-200 KB
Glide 代码:
在 GridViewAdapter 中
RequestOptions reqOpt = RequestOptions.fitCenterTransform().transform(new RoundedCorners(5));
...
GlideApp
.with(context)
.load(item.getUrl())
.apply(reqOpt)
.placeholder(R.drawable.place_holder)
.into(holder.ivThumb);
在 Gradle 中
...
implementation 'com.github.bumptech.glide:glide:4.7.1'
annotationProcessor 'com.github.bumptech.glide:compiler:4.7.1'
...
最佳答案
试试这个,
它将优化您加载图像的内存。
RequestOptions reqOpt = RequestOptions
.fitCenterTransform()
.transform(new RoundedCorners(5))
.diskCacheStrategy(DiskCacheStrategy.ALL) // It will cache your image after loaded for first time
.override(holder.ivThumb.getWidth(),holder.ivThumb.getHeight()) // Overrides size of downloaded image and converts it's bitmaps to your desired image size;
从这里查看更多信息:Glide reference
关于java - GridView 中使用 Glide 加载图像太慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52325773/