如何提高我的 Recyclerview 持有从 Firebase 检索的图像的性能? (Android)
How to improve the performance of my Recyclerview holding images retrieved from Firebase? (Android)
这可能看起来像是一个普遍的重复问题,但实际上,我想知道这段代码是否有任何改进的机会,因为我从其他人那里了解到的是“ 中的代码onBindViewHolder()" 应该足够有效,不会减慢 RecyclerView 的速度。
@Override
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
holder.itemView.getLayoutParams().width = (widthPixels / 2) - 28;
StorageReference sr = images.get(position);
GlideApp.with(holder.itemView.getContext())
.load(sr)
.thumbnail(0.2f)
.placeholder(R.drawable.background_splash)
.into(holder.album);
holder.albumTitle.setText(giveName(sr.getName()));
ViewCompat.setTransitionName(holder.itemView, "Wall" + (position + 1) + "_Transition");
}
目前,我没有很多图像可以从 Firebase 访问,但假设数字变为 500,这部分代码会对长运行?
(我也知道了一个叫做“DiffUtil”的东西,但现在不想尝试新的东西。)
(我的应用程序的完整代码,如果这很重要:https://github.com/Sujal1245/WALLisWALL-Wallpaper-App)
Currently, I don't have many images to access from the Firebase but suppose the number turns to something like 500, will this part of the code do any harm in the long run?
这与您的代码的特定部分无关,因为它与您下载的数据量有关。一次请求所有这 500 张图像不是推荐的方法。除此之外,我认为没有人会对看到所有这些图像感兴趣。更不用说这将花费大量时间。所以你最好的选择是限制你阅读的图片数量。
你怎样才能做到这一点?只需将每个图像的 URL 存储在 Cloud Firestore or in the Realtime Database, and read them in smaller chunks. A common approach would be to always display the exact number of images that you are able to display on the screen. That being said, you should consider getting data progressively. You can also consider implementing pagination 中(如果您的应用的用例需要它)。
I also got to know about something called "DiffUtil" but don't want to experiment on something new right now.
根据docs:
DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.
因此,如果您仍然考虑一次下载所有这 500 张图像,DiffUtil 不会为您节省带宽。
这可能看起来像是一个普遍的重复问题,但实际上,我想知道这段代码是否有任何改进的机会,因为我从其他人那里了解到的是“ 中的代码onBindViewHolder()" 应该足够有效,不会减慢 RecyclerView 的速度。
@Override
public void onBindViewHolder(@NonNull ImageViewHolder holder, int position) {
holder.itemView.getLayoutParams().width = (widthPixels / 2) - 28;
StorageReference sr = images.get(position);
GlideApp.with(holder.itemView.getContext())
.load(sr)
.thumbnail(0.2f)
.placeholder(R.drawable.background_splash)
.into(holder.album);
holder.albumTitle.setText(giveName(sr.getName()));
ViewCompat.setTransitionName(holder.itemView, "Wall" + (position + 1) + "_Transition");
}
目前,我没有很多图像可以从 Firebase 访问,但假设数字变为 500,这部分代码会对长运行?
(我也知道了一个叫做“DiffUtil”的东西,但现在不想尝试新的东西。)
(我的应用程序的完整代码,如果这很重要:https://github.com/Sujal1245/WALLisWALL-Wallpaper-App)
Currently, I don't have many images to access from the Firebase but suppose the number turns to something like 500, will this part of the code do any harm in the long run?
这与您的代码的特定部分无关,因为它与您下载的数据量有关。一次请求所有这 500 张图像不是推荐的方法。除此之外,我认为没有人会对看到所有这些图像感兴趣。更不用说这将花费大量时间。所以你最好的选择是限制你阅读的图片数量。
你怎样才能做到这一点?只需将每个图像的 URL 存储在 Cloud Firestore or in the Realtime Database, and read them in smaller chunks. A common approach would be to always display the exact number of images that you are able to display on the screen. That being said, you should consider getting data progressively. You can also consider implementing pagination 中(如果您的应用的用例需要它)。
I also got to know about something called "DiffUtil" but don't want to experiment on something new right now.
根据docs:
DiffUtil is a utility class that calculates the difference between two lists and outputs a list of update operations that converts the first list into the second one.
因此,如果您仍然考虑一次下载所有这 500 张图像,DiffUtil 不会为您节省带宽。