LazyColumn 在卡片中包含标题项目,在卡片中包含剩余项目 [英] LazyColumn with header item in card and remaining items in card

查看:34
本文介绍了LazyColumn 在卡片中包含标题项目,在卡片中包含剩余项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 compose LazyColumn 我想要一张用于标题项目的卡片,以及一张包含其余项目的卡片.

Using compose LazyColumn I would like a card for the header item, and a single card that contains the remaining items.

LazyColumn() {
  item {
    Card() { // header card}
  }

  // would like all items in single card
  Card() { // cannot do this, outside composable function
      items(myItems) { item ->
         // item here
      }
  }
}

这样的事情有可能吗?

推荐答案

如果您只有 2 个项目,那么拥有 LazyColumn 是没有意义的.在这种情况下,如果需要,请使用带有 verticalScroll 的常规 Column:

There is no point to have a LazyColumn if you just have 2 items. In this case, use a regular Column with verticalScroll if you need to:

Column(
    modifier = Modifier
        .fillMaxWidth()
        .verticalScroll(
            rememberScrollState()
        ),
) {
    Card(
        modifier = Modifier.fillMaxWidth()
    ) {
        header()
    }
    Card(
        modifier = Modifier.fillMaxWidth()
    ) {
        Column {
            item1()
            item2()
        }
    }
}

这篇关于LazyColumn 在卡片中包含标题项目,在卡片中包含剩余项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆