简体   繁体   English

我应该选择哪个 Recyclerview 或 ScrollView?

[英]Which Recyclerview or ScrollView should I choose?

I created an activity with a ListView .我用ListView创建了一个活动。 That is a Friend ListView .那是一个 Friend ListView

I wanna let it choose to add it to another View .我想让它选择将它添加到另一个View

I don't know which View to choose is the best.我不知道选择哪种View最好。 Recyclerview or ScrollView ? Recyclerview还是ScrollView

Like this像这样

在此处输入图片说明

Basic difference between RecyclerView and ListView are the below. RecyclerViewListView之间的基本区别如下。

ListView is simple to implement. ListView实现起来很简单。 Default Adapters available.默认适配器可用。 But ViewHolder pattern and finding views using ID's used to give slow performance.但是ViewHolder模式和使用 ID 查找视图过去常常会降低性能。

Now in RecyclerView , the above problems are attended using RecyclerView.ViewHolder .现在在RecyclerView ,使用RecyclerView.ViewHolder解决了上述问题。 For RecyclerView adapter, this ViewHolder is mandatory.对于RecyclerView适配器,此ViewHolder是必需的。 While comparing to list view this is kinda complex, but solves performance issues in ListView .虽然与列表视图相比这有点复杂,但解决了ListView性能问题。

Difference LayoutManagers are available while using RecyclerView .使用RecyclerView可以使用差异LayoutManagers

Major improvement of RecyclerView performance while comparing to ListView would be this according to developer.android.com根据developer.android.com,与 ListView 相比,RecyclerView 性能的主要改进是

The RecyclerView creates only as many view holders as are needed to display the on-screen portion of the dynamic content, plus a few extra. RecyclerView 只创建显示动态内容的屏幕部分所需的视图持有者,再加上一些额外的。 As the user scrolls through the list, the RecyclerView takes the off-screen views and rebinds them to the data which is scrolling onto the screen当用户滚动列表时,RecyclerView 获取屏幕外视图并将它们重新绑定到滚动到屏幕上的数据

To sumup, RecyclerView is preferable than ListView (when UI is having same widgets repeating according to your data)总而言之,RecyclerView 比 ListView 更可取(当 UI 具有根据您的数据重复的相同小部件时)



Now when to use ScrollView :现在何时使用ScrollView

Your UI elements may not show completely in small device screens.您的 UI 元素可能无法在小设备屏幕中完全显示。 But in bigger screen sizes it may!但在更大的屏幕尺寸中它可能! Elements may not be necessarily only list / grid.元素可能不一定只是列表/网格。 It can have combinations of any UI widgets.它可以具有任何 UI 小部件的组合。

Eg:- TextViews vertically , with RadioButton and Button at last for user action.例如:- TextViews垂直,最后使用RadioButtonButton用于用户操作。

This cannot be included in ListView / RecyclerView , now you can add ScrollView which will have a LinearLayout / RelativeLayout .这不能包含在ListView / RecyclerView ,现在您可以添加具有LinearLayout / RelativeLayout ScrollView Inside which all other elements can be added.可以在其中添加所有其他元素。

Now you can现在你可以

I recommend to user always RecyclerView and never a ListView.我建议用户始终使用 RecyclerView 而不要使用 ListView。 Use RecyclerView for element list and scrollview for static views.对元素列表使用 RecyclerView,对静态视图使用滚动视图。

Seeing your image Scrollview inside RecyclerView or ListView have problems with drag.在 RecyclerView 或 ListView 中看到您的图像 Scrollview 有拖动问题。

Use a vertical RecyclerView in all page and horizontal RecyclerView each row.在所有页面中使用垂直 RecyclerView,每行使用水平 RecyclerView。

I suggest you to use RecyclerView because you will load lots of images and if you use ScrollView eventually you will use so much memory.我建议您使用 RecyclerView,因为您将加载大量图像,如果您最终使用 ScrollView,您将使用大量内存。 Also it is recommended to use RecyclerView when you have dynamic data.此外,当您有动态数据时,建议使用 RecyclerView。 You can look the definition of the RecyclerView in the Android Documentation as follow您可以查看 Android 文档中 RecyclerView 的定义如下

RecyclerView is a view for efficiently displaying large data sets by providing a limited window of data items. RecyclerView 是一种通过提供有限的数据项窗口来有效显示大型数据集的视图。

You can use nested RecyclerView for creating such hierarchal view.您可以使用嵌套的 RecyclerView 来创建这样的分层视图。 You can also checkout this example for nested RecyclerView usage.您还可以查看此示例以了解嵌套的 RecyclerView 用法。

Also you can further read:您也可以进一步阅读:

I hope this helps.我希望这有帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM