简体   繁体   English

Android Compose:LazyColumn和Column with verticalScroll的区别

[英]Android Compose: Difference between LazyColumn and Column with verticalScroll

I tried to look for reasons to use LazyColumn vs Column with verticalScroll .我试图寻找将LazyColumnColumnverticalScroll一起使用的原因。 What is the difference between them?它们之间有什么区别? Like why would one be an ideal choice compare to other.就像为什么与其他人相比,一个人会是一个理想的选择。 They both make screen scrollable, isn't it?它们都使屏幕可滚动,不是吗? Would choosing one over the other one be wrong in any case?在任何情况下选择一个而不是另一个是错误的吗?

LazyColumn 懒人列

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. LazyColumn 是一个垂直滚动的列表,它只组合和布置当前可见的项目。 It's similar to a Recyclerview in the classic Android View system.它类似于经典的 Android View 系统中的 Recyclerview。

Column 柱子

A Column will show each child below the previous children.一个列将在之前的孩子下方显示每个孩子。 It's similar to a LinearLayout with vertical orientation.它类似于具有垂直方向的 LinearLayout。

Imagine that you want to display a large amount of data with an unknown number of items.想象一下,您想显示包含未知数量项目的大量数据。 If you decide to use a Column/Row layout, this could translate into a lot of performance issues because all the items will compose whether they're visible or not.如果您决定使用Column/Row布局,这可能会转化为许多性能问题,因为所有项目都会组合起来,无论它们是否可见。 The Lazy option lets you lay out the components when they're visible. Lazy选项可让您在组件可见时对其进行布局。 Resulting in much better performance when dealing with larger amount of elements in list/grid在处理列表/网格中的大量元素时产生更好的性能

LazyColumn is RecyclerView counterpart of View while Column with verticalScroll is ScrollView counterpart. LazyColumn 是 View 的 RecyclerView 对应物,而带有 verticalScroll 的 Column 是 ScrollView 对应物。

Any Composable inside Column with vertical scroll enters composition the moment Column is composed while LazyColumn uses SubcomposeLayout to subcompose Composables on screen and one extra when you reach last visible item on Screen.任何在 Column 中具有垂直滚动的 Composable 都会在 Column 被组合时进入组合,而 LazyColumn 使用SubcomposeLayout在屏幕上对 Composables 进行子组合,当您到达屏幕上的最后一个可见项目时会额外添加一个。

Also LazyColumn offers some features where Column doesn't LazyColumn 还提供了一些 Column 没有的功能

flingBehavior: FlingBehavior = ScrollableDefaults.flingBehavior()

let's so you easily implement flingBehavior especially with 1.3.0-beta02 update with rememberSnapFlingBehavior()让我们轻松实现 flingBehavior,尤其是使用rememberSnapFlingBehavior()更新 1.3.0-beta02

Also rememberLazyListState() provides information about first item index, offset and layoutInfo and visible items which enables more customization than rememberScrollState() like this color and scale animation using visible item positions.此外, rememberLazyListState()提供有关第一个项目索引、偏移量和 layoutInfo 以及可见项目的信息,这比rememberScrollState()支持更多的自定义,例如使用可见项目位置的颜色和缩放 animation

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

相关问题 具有verticalScroll修饰符的Column内的LazyColumn抛出异常 - LazyColumn inside Column with verticalScroll modifier throws exception VerticalScroll 在 Jetpack 撰写列中不起作用 - VerticalScroll is not working in the Jetpack compose column android:jetpack composelazycolumn - android: jetpack compose lazycolumn 如何在 LazyColumn Jetpack Compose 中的项目之间添加分隔符? - How to add dividers between items in a LazyColumn Jetpack Compose? Jetpack Compose:带有verticalScroll修饰符的列中的LazyVerticalGrid抛出java.lang.IllegalStateException - Jetpack Compose:LazyVerticalGrid within Column with verticalScroll modifier throws java.lang.IllegalStateException 在 Jetpack Compose 中使用 Column 而不是 LazyColumn 来关闭材料滑动 - Material Swipe To Dismiss in Jetpack Compose with a Column instead of a LazyColumn 如何在 Android Compose 中的 LazyColumn 项周围绘制边框 - How to draw border around the LazyColumn items in Android Compose 如何在 Jetpack Compose Android 的 LazyColumn 中显示项目视图的动画 - How to show animate an item view in LazyColumn on Jetpack Compose Android Jetpack Compose – LazyColumn 不重组 - Jetpack Compose – LazyColumn not recomposing Jetpack Compose 惰性列性能 - Jetpack Compose lazycolumn performance
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM