在 viewpager 中的 recyclerview 中加载大数据的性能问题 [英] Performance issue with loading large data in recyclerview in a viewpager

查看:105
本文介绍了在 viewpager 中的 recyclerview 中加载大数据的性能问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的设置包括两个带有 viewpager 的选项卡设置.每个选项卡都包含一个片段,其中包含一个显示歌曲列表的 recyclerview.问题是,当将大量歌曲加载到 recyclerview 时,ui 会冻结一段时间.对于超过 2000 首歌曲,系统长时间冻结,然后抛出 OutOfMemory 错误.

My setup consists of two tabs setup with viewpager. Each tab contains a fragment which contains a recyclerview that displays list of songs. The issue is, when loading large amount of songs into the recyclerview, the ui just freezes up for some time. For number of songs above 2000, the systems freezes for a long time and afterwards throws an OutOfMemory error.

注意:即使数据集非常大,将数据以简单的片段或活动加载到 recyclerview 中也完全没有性能问题.

Note: The loading of data into the recyclerview in a simple fragment or activity has no performance issues at all even when the data set is very large.

我该如何优化?

推荐答案

于是我找到了问题的根源.NestedScrollView 中的 Recyclerview.因为我要显示三个 RecyclerView,所以我不得不使用 NestedScrollView 来包装它们.但是从这个问题,我知道在nestedScrollView 中使用recyclerview 将使recyclerview 想要在渲染它们之前立即创建所有视图.所以这就是每次显示数据时 UI 冻结的原因.

So I found the root course of the problem. Recyclerview inside NestedScrollView. Because I have like three RecyclerViews to display, I had to use NestedScrollView to wrap them. But then from this question, I understood that having recyclerview inside nestedScrollView will make the recyclerview want to create all the views at once before rendering them. So that was why the UI froze each time data is to be displayed.

这篇关于在 viewpager 中的 recyclerview 中加载大数据的性能问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆