使具有可滚动内容的选项卡与父可组合项一起滚动 - IllegalException:无限最大高度

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

我有一个可组合屏幕,其中包含一些内容,然后是一个 TabRow,其中包含不同的屏幕(取决于所选选项卡)。选项卡屏幕包含可滚动数据,这是使用 LazyColumn 显示的。

在父屏幕上,我只有一个父列。我希望此列以及选项卡屏幕上的内容都是可滚动的。 (因为方向改变、屏幕尺寸小等。请参阅附图)。

问题是我不能让我的父屏幕列同时让选项卡屏幕使用 LazyColumn。我收到错误:

java.lang.IllegalStateException: 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.

如何实现让父屏幕可滚动(对于较小的屏幕)以及选项卡屏幕中的内容也可滚动的目标?

enter image description here

enter image description here

android android-jetpack-compose android-jetpack-compose-material3 lazycolumn android-jetpack-compose-lazy-column
1个回答
0
投票

回答任何面临类似挑战的人:

我发现了 LazyListScope。因此,我没有为每个选项卡创建另一个可组合项,而是在父可组合项中创建了一个函数,该函数加载要回收的列表。我还将父列更改为 LazyColumn,并将其中的内容作为单独的项目添加。

这是我的新 LazyListScope 函数:

fun LazyListScope.transactionsScreen() {
    val transactions = listOf(
       // Transaction items here
    )
    itemsIndexed(transactions){index, transaction ->
        TransactionItem(transaction = transaction)
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.