Lazy layouts in Compose
Why Stack Overflow recommends it
Stack Overflow users link it when answering questions about nesting scrollable Compose components like a LazyColumn inside a vertically scrolling Column, which crashes or throws an IllegalStateException.
Recommended by 4 people across 3 different months, 2022 to 2023.
What it is
A Google I/O 2022 session from the Android team on Jetpack Compose lazy layouts such as LazyColumn and LazyRow. It covers how they work under the hood, why to use unique item keys, and why to avoid nested same-direction scrolling and zero-pixel items, and it previews lazy grids and item animations.
What people said
Recommends Kaaveh Mohamedi · 2022-05 · Stack Overflow · on “Use Jetpack Compose vertically scrollable component in ConstraintLayout”
I figure out that the LazyColumn I used in Column parent with Modifier .verticalScroll(rememberScrollState()) is the source of crash. As a Google I/O talk, you shouldn't use nesting components scrollable in the same direction. For more info on why and what is the solution, check out this talk [this video] .
Recommends Phil Dukhov · 2022-05 · Stack Overflow · on “Jetpack Compose: nested LazyColumn / LazyRow”
Check out this [this video] youtube video about the topic as well as this answer [LINK] for a basic example - shortly you can place your subcomments in a separate `item`/`items`. Also this answer [LINK] may be useful for building a dynamic items tree.
Recommends Nikhil Dupally · 2022-09 · Stack Overflow · on “When adding lazy column inside another lazy column in android jetpack compose it shows error”
you can check [this video] youtube video about the topic as well as [LINK] answer for a basic example - shortly you can place your content in a separate item/items. Also this [LINK] answer may be useful for building a dynamic items tree.
Recommends Faruk · 2023-10 · Stack Overflow · on “LazyColum and component with infinity maximum height”
You should not use nesting components that can be scrolled in the same direction. Lazy layouts in Compose [this video]
Cites Alvin Dizon · 2022-06 · Stack Overflow · on “LazyColumn with header item in card and remaining items in card”
You can have something like this: Card { Column { Text(text = "Header") LazyColumn { items(myItems) { // ... } } } } But note that this can run into an IllegalStateException if you try to have an outer composable scroll in the same direction as well...but if you specify a specific height for your LazyColumn then it should be fine. See this video [this video] about nesting same-direction columns:
Cites JHowzer · 2022-09 · Stack Overflow · on “How to create a Card with a lazy vertical list of items that can be nested within a scrollable Column using Compose?”
I'd like to have a Compose UI that is something like this (overly-simplified version)... [LINK] Each carded list below each group is variable length depending on the list of items fed to the composable. Here's two options for how to approach this (using either a Column or LazyColumn ): @Composable fun CardedColumn(items: ImmutableList<String>) { Card(modifier = Modifier.fillMaxWidth().wrapContentHeight().padding(8.dp)) { Column { items.forEach { text: String -> Text(text = text, modifier = Modifier.padding(8.dp)) Divider(modifier = Modifier.fillMaxWidth()) } } } } @OptIn(ExperimentalFoundationApi::class) @Composable fun CardedLazyColumn(items: ImmutableList<String>) { Card(modifier = Modifie
Cites Yogendra · 2023-05 · Stack Overflow · on “What is the Jetpack Compose equivalent of RecyclerView or ListView?”
LazyColumn and LazyRow are euquavalant to Recycleview. /* * * LazyColumn produces a vertically scrolling list, * LazyRow produces a horizontally scrolling list. * * */ @Composable fun addUserList(userDataList: List<User>) { val context = LocalContext.current Column( modifier = Modifier .fillMaxSize() .fillMaxWidth() .fillMaxHeight() ) { LazyColumn( contentPadding = PaddingValues(horizontal = 16.dp, vertical = 16.dp), verticalArrangement = Arrangement.spacedBy(3.dp), ) { // header item { Text(text = "I'm header.") } // main content items( userDataList, itemContent = { user -> Row( modifier = Modifier .fillMaxWidth() .clickable { context.showToast("you clicked ${user.name}") }, verticalAlignme
Cites Сергей Беляков · 2023-07 · Stack Overflow · on “Multiple scrolls with element fixation in Compose”
@Abhimanyu I tried to solve the problem by adding the .height() modifier to the LazyVerticatlGrid. Don't know how dirty this hack is. Example: [this video]
Cites Faruk · 2023-11 · Stack Overflow · on “Nested Scrolling in Android using Jetpack Compose”
Avoid nesting components that can scroll in the same direction. While this is permitted in Android XML structure, Compose discourages this practice. If you're already using LazyColumn, you'll be able to scroll down when the content doesn't fit on the screen. Lazy Layout in Compose [this video]