Lazy Column 可以存在于另一个 Lazy Column 中吗?

发布于 2025-01-12 01:59:31 字数 883 浏览 1 评论 0原文

我开始使用 Jetpack compose,但在 Lazy Column 方面遇到了一些问题。

问题是我想创建一个列表,其中每个根项中包含另一个列表(例如内部包含另一个列表的卡片)。

不幸的是,当我运行以下代码时(在恢复我正在尝试执行的操作的代码片段下方)。

我发现了异常:

java.lang.IllegalStateException:垂直可滚动组件是用无限最大高度约束测量的,这是不允许的。常见原因之一是嵌套布局,例如 LazyColumn 和 Column(Modifier.verticalScroll())。如果您想在项目列表之前添加标题,请在 LazyColumn 范围内的主 items() 之前添加一个标题作为单独的 item() 。发生这种情况可能还有其他原因:您的 ComposeView 被添加到具有一定权重的 LinearLayout 中、您应用了 Modifier.wrapContentSize(unbounded = true) 或编写了自定义布局。请尝试消除滚动容器上方层次结构中无限约束的来源。

代码:

LazyColumn(modifier = Modifier.wrapContentHeight()) {
    items(list.value) { 
        item -> LazyColumn(modifier = Modifier.wrapContentHeight()) {
            //some Text
        }
    }
}

我不需要嵌套的 Lazy Column 可滚动,所以我想知道为此目的是否有另一个元素可以使用而不是 LazyColumn,或者我犯了一些其他错误。

我还尝试按照异常的建议将其他布局元素放入 item{} 块中,但结果相同。

I'm starting using Jetpack compose and i'm facing some issues with Lazy Column.

The problem is that i want to make a list that contains another list inside every root item (such as a card that containt another list inside).

Unfortunately, when i run the following code (below the snippet that resume what i'm trying to do).

I catch the exception:

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.

Code:

LazyColumn(modifier = Modifier.wrapContentHeight()) {
    items(list.value) { 
        item -> LazyColumn(modifier = Modifier.wrapContentHeight()) {
            //some Text
        }
    }
}

I don't need the nested Lazy Column to be scrollable, so i'm wondering if for this purpose there is another element to use instead of LazyColumn, or i'm making some other mistake.

I've also tried to put in item{} block other layout elements, as suggested by the Exception, but with the same result.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

妖妓 2025-01-19 01:59:31

不,不幸的是,不允许在同一方向嵌套可滚动可组合项。

No, unfortunately, nesting scrollable composables in the same direction is not allowed.

汹涌人海 2025-01-19 01:59:31

jetpack compose 不支持它,但我认为应该支持它,因为许多用例都需要它。例如电子商务应用程序、食品配送(如 DoorDash)

It's not supported in jetpack compose, but I think it should be supported because many use cases need that. e.g e-commerce applications,food delivery (like DoorDash)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文