Java Glide使用URL从firebase加载图像的速度非常慢

Java Glide使用URL从firebase加载图像的速度非常慢,java,android-studio,kotlin,android-recyclerview,android-glide,Java,Android Studio,Kotlin,Android Recyclerview,Android Glide,我正在尝试创建一个RecyclerView,它由每个单元格中的ImageView填充,每个图像对应于Firebase存储中的一个图像。 我有一个字符串列表,这些字符串被传递到我的RecyclerView适配器中,每个字符串表示Firebase存储中一个图像的URL。我将每个图像加载到onBindViewHolder()中 我得到的回报是非常缓慢地加载一些图像(大约5张,见图),然后加载另外5张图像大约需要4分钟,之后似乎再也不会加载任何其他图像 我读过多篇关于StackOverflow的帖子,但

我正在尝试创建一个RecyclerView,它由每个单元格中的ImageView填充,每个图像对应于Firebase存储中的一个图像。 我有一个字符串列表,这些字符串被传递到我的RecyclerView适配器中,每个字符串表示Firebase存储中一个图像的URL。我将每个图像加载到
onBindViewHolder()

我得到的回报是非常缓慢地加载一些图像(大约5张,见图),然后加载另外5张图像大约需要4分钟,之后似乎再也不会加载任何其他图像

我读过多篇关于StackOverflow的帖子,但大多数帖子只是告诉您使用
fitCenter()
centerCrop()
,但这并没有改变我的情况。我也在Glide的文档中读到Glide会自动减少图像的采样,所以我不需要手动进行,对吗?你知道我可能做错了什么吗?Url字符串成功地从Firebase中检索,查询几乎立即得到解决,因此我认为没有任何问题

更新: 我在
onBindViewHolder()
方法中做了一些修改,以便从Glide显式请求图像缓存,并且我还使用
缩略图API
下载图像的较低分辨率。现在正在加载更多的图像,但每个图像仍然需要大约7秒的时间来加载,这显然太长了。如果你有任何建议,请告诉我

以下是如何在我的主要活动中设置RecyclerView:

iconsRCV = findViewById(R.id.cardIconsRCV)
iconsRCV.layoutManager = GridLayoutManager(this,5) // set the layout manager for the rcv
val iconUrls : ArrayList<String> = ArrayList() // initialize the data with an empty array list
val adapter = CardIconAdapter(this,iconUrls) // initialize the adapter for the recyclerview
iconsRCV.adapter = adapter // set the adapter


另外,Firebase中的图像大小大多为udner 200KB,但也有少数达到4MB。另外,
R.layout.card\u icons\u rcv\u项目中的ImageView的大小为75x75。

希望您使用了最新版本的glide。 有几种方法可以更好地加载和缓存图像, 这是我的功劳

1。启用磁盘缓存

 val requestOptions = RequestOptions().diskCacheStrategy(DiskCacheStrategy.ALL)
 Glide.with(context).load(url).apply(requestOptions).into(imageView)
2。列表项

val requestOptions = RequestOptions()
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .signature(ObjectKey(signature))

Glide.with(context).load(url).apply(requestOptions).into(imageView)
3。覆盖图像大小(可选)

4。添加缩略图Url

val requestOptions = RequestOptions()
        .diskCacheStrategy(DiskCacheStrategy.ALL)
        .signature(ObjectKey(signature))
        .override(100, 100) // resize does not respect aspect ratio

Glide.with(context).load(url).apply(requestOptions).into(imageView)
// With thumbnail url
Glide.with(context).load(url)
        .thumbnail(Glide.with(context).load(thumbUrl))
        .apply(requestOptions).into(imageView)

// Without thumbnail url

// If you know thumbnail size
Glide.with(context).load(url)
        .thumbnail(Glide.with(context).load(url).apply(RequestOptions().override(thumbSize)))
        .apply(requestOptions).into(imageView)

// With size multiplier
Glide.with(context).load(url)
        .thumbnail(0.25f)
        .apply(requestOptions).into(imageView)
5。设置每月清洁时间表

// This method must be called on the main thread.
Glide.get(context).clearMemory()

Thread(Runnable {
    // This method must be called on a background thread.
    Glide.get(context).clearDiskCache()
}).start()
6。要转换位图

      // TODO remove after transformation is done
        .diskCacheStrategy(SOURCE) // override default RESULT cache and apply transform always
        .skipMemoryCache(true) // do not reuse the transformed result while running
        .diskCacheStrategy(DiskCacheStrategy.ALL) // It will cache your image after loaded for first time
        .format(DecodeFormat.PREFER_ARGB_8888) //for better image quality
        .dontTransform() // to load image faster just skip transform 
        .placeholder(R.drawable.placeholder) // use place holder while image is being load

您是否尝试使用glide缓存图像?@Radhey glide不会自动缓存图像?您是否尝试加载较小尺寸的图像?是的,它会自动管理,但也取决于glide版本。作为参考,还可以使用
diskCacheStrategy(diskCacheStrategy.ALL)
缩略图API
@Radhey,这大大改进了加载。您是否介意提交并回答,同时检查我在这里遇到的一些RecyclerView问题的最新问题:?这实际上就是您在评论部分链接的文章所说的一切。可悲的是,正如我在评论中提到的,所有这些都没有使任何fasterit的加载在glide实现中没有任何问题。每次在适配器类的onBindViewHolder()内都要创建
requestOptions
对象。在类级别全局创建该对象并再次检查。嗯,现在似乎加载速度加快了,但每个图标仍然需要1-2秒,这看起来很慢,对吗?它们似乎是按顺序加载的,难道它们不能以某种方式并行加载吗?我想知道reddit、facebook、imgur等应用程序是如何以如此高的分辨率如此快速地加载图像的?我只是发布了可以在stackoverflow上找到的最大策略,而不是直接形成博客。你可以接受的答案,如果它即兴你的加载时间。因此,您需要更改适配器代码。让我检查一下。您能用适配器和glide实现再次更新您的问题吗?您在最后尝试了什么!
      // TODO remove after transformation is done
        .diskCacheStrategy(SOURCE) // override default RESULT cache and apply transform always
        .skipMemoryCache(true) // do not reuse the transformed result while running
        .diskCacheStrategy(DiskCacheStrategy.ALL) // It will cache your image after loaded for first time
        .format(DecodeFormat.PREFER_ARGB_8888) //for better image quality
        .dontTransform() // to load image faster just skip transform 
        .placeholder(R.drawable.placeholder) // use place holder while image is being load