包含列表的 CardView 列表。 LinearLayout 还是 RecyclerView?
List of CardViews containing lists. LinearLayout or RecyclerView?
我正在尝试创建下面的布局。
布局由 3-4 个卡片视图组成。在两个 cardviews 中将是长度在 0-6 项之间的任何短列表。
我想知道,因为所有的卡片都不一样,而且数量很少,如果使用 RecyclerView 而不是 LinearLayout 有什么好处。
在我看来,由于卡片都是异构的,因此 RecyclerView 不会有任何视图 'recycle'。或者我错过了什么?
你错过了一件大事内存消耗,在RecyclerView屏幕中需要更少的内存 因为只有可见的视图在内存中。在 LinearLayout 中,您将始终需要内存中的所有视图,这意味着 更多堆内存。
您的应用程序使用的内存越多,它就越容易出现 GC 周期,这将导致 jankyness 或缓慢 应用程序行为。
It seem to me that since the cards are all heterogeneous there
wouldn't be any views the RecyclerView could 'recycle'.
您完全正确 - 您无法通过使用其他 RecyclerView
的项目数据来重复使用视图 (ViewHolders
) 来获利。
您 show/describe 的布局不是 集合 的典型示例,它看起来很简单(轻),因此在您的情况下没有实现的意义RecyclerView
及其 Adapter
.
I am wondering since all the cards are different and there so few of
them if there would be any benefit to using a RecyclerView over a
LinearLayout.
问问自己,如果您的项目是 FrameLayouts
,您是否会考虑 RecyclerView
?总而言之,CardView
只是一个 FrameLayout
加了点装饰:)
我个人会使用 ScrollView
+ LinearLayout
。这种方法实施起来更快,也更容易维护。
我也同意 @Ben P. 所写的内容 - 如果最简单的解决方案满足您的需求,则没有必要对其进行优化。
我正在尝试创建下面的布局。
布局由 3-4 个卡片视图组成。在两个 cardviews 中将是长度在 0-6 项之间的任何短列表。
我想知道,因为所有的卡片都不一样,而且数量很少,如果使用 RecyclerView 而不是 LinearLayout 有什么好处。
在我看来,由于卡片都是异构的,因此 RecyclerView 不会有任何视图 'recycle'。或者我错过了什么?
你错过了一件大事内存消耗,在RecyclerView屏幕中需要更少的内存 因为只有可见的视图在内存中。在 LinearLayout 中,您将始终需要内存中的所有视图,这意味着 更多堆内存。 您的应用程序使用的内存越多,它就越容易出现 GC 周期,这将导致 jankyness 或缓慢 应用程序行为。
It seem to me that since the cards are all heterogeneous there wouldn't be any views the RecyclerView could 'recycle'.
您完全正确 - 您无法通过使用其他 RecyclerView
的项目数据来重复使用视图 (ViewHolders
) 来获利。
您 show/describe 的布局不是 集合 的典型示例,它看起来很简单(轻),因此在您的情况下没有实现的意义RecyclerView
及其 Adapter
.
I am wondering since all the cards are different and there so few of them if there would be any benefit to using a RecyclerView over a LinearLayout.
问问自己,如果您的项目是 FrameLayouts
,您是否会考虑 RecyclerView
?总而言之,CardView
只是一个 FrameLayout
加了点装饰:)
我个人会使用 ScrollView
+ LinearLayout
。这种方法实施起来更快,也更容易维护。
我也同意 @Ben P. 所写的内容 - 如果最简单的解决方案满足您的需求,则没有必要对其进行优化。