3

I want to use the lazy column under the lazy column and have a vertical scroll view in it. While using the vertical scroll in it, I had issues. Can anyone help me create a Nested Scroll view?

  • Lazy column under lazy column
  • Need to have vertical scroll in which container other body section also

Issues which i have face while using lazy column under lazy column.[![Error Image][1]][1]

@Composable
fun NestedColumn() {

    LazyColumn() {

        item { }

        items(200){
            Text(text = "This is Inner Nested")

            LazyColumn(){

                item {  }

                items(50) {
                    Text(text = "This is Inner inner Nested")
                }
            }

        }
    }
}```


  [1]: https://i.sstatic.net/1lTkD.png


Error Message:

Vertically scrollable component was measured with an infinity maximum height constraints, which is disallowed. One of the common reasons is nesting layouts like LazyColumn and Column(Modifier.verticalScroll()). If you want to add a header before the list of items please add a header as a separate item() before the main items() inside the LazyColumn scope. There are could be other reasons for this to happen: your ComposeView was added into a LinearLayout with some weight, you applied Modifier.wrapContentSize(unbounded = true) or wrote a custom layout. Please try to remove the source of infinite constraints in the hierarchy above the scrolling container.
3
  • 1
    Does this answer your question? Jetpack Compose: nested LazyColumn / LazyRow Commented Sep 19, 2023 at 13:55
  • @SevbanBayır No, I want Lazy Column under items section as well. Commented Sep 21, 2023 at 4:57
  • I know you want that but it is not possible with the way you are doing and the ways that are possible are aclared in the question i forwarded. There are restrictions and you have to comply your code to them. Commented Sep 21, 2023 at 5:11

3 Answers 3

2

I suggested to you that you should handle it another way as it's not a professional way to handle nested lazy columns.

  • You can handle it with a set fixed height to one of the lazy columns
  • Handle with just one Lazy column and manage with item{} and items{} in it.
Sign up to request clarification or add additional context in comments.

1 Comment

I have tired of using the fixed height, but if there are large items or fewer items, the fixed height won't help.
1

You can implement a nested LazyColumn in Jetpack Compose using fillParentMaxSize() to manage the size of the inner LazyColumn. Here's how you can do it:

LazyColumn(modifier = Modifier.fillMaxSize()) {
item {
    Text(text = "Outer Item 1", modifier = Modifier.padding(8.dp))
}
item {
    LazyColumn(modifier = Modifier.fillParentMaxSize()) {
        items(50) { innerIndex ->
            Text(
                text = "Inner Item #$innerIndex",
                modifier = Modifier.padding(8.dp)
            )
        }
    }
}

}

Comments

0

Just need add FlowColumn from Compose and don't you need add another Column inside your contained Itementer image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.