JetpackCompose 中的嵌套惰性列

问题描述 投票:0回答:2

我想使用惰性列下的惰性列,并在其中有一个垂直滚动视图。在使用垂直滚动时,我遇到了问题。谁能帮我创建一个嵌套滚动视图?

  • 懒惰列下的懒惰列
  • 容器其他主体部分也需要垂直滚动

我在惰性列下使用惰性列时遇到的问题。[![错误图像][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.stack.imgur.com/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.
android android-jetpack-compose android-nestedscrollview android-jetpack-compose-lazy-column
2个回答
2
投票

我建议您应该以另一种方式处理它,因为这不是处理嵌套惰性列的专业方法。

  • 您可以通过为惰性列之一设置固定高度来处理它
  • 仅处理一个 Lazy 列,并使用其中的 item{} 和 items{} 进行管理。

0
投票

只需要从 Compose 添加 FlowColumn,不需要在包含的 Item 中添加另一个列enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.