创建垂直分隔线JetpackCompose

如何使用 Jetpack Compose 创建垂直分隔线?我尝试使用 Spacer 和 Box 来做到这一点,但它根本没有出现。这是我尝试过的:

Box(
    modifier = Modifier
        .fillMaxHeight()
        .width(2.dp)
        .background(color = Color.Black)
)

但这根本行不通。那么如何在 Jetpack Compose 中做垂直分隔线呢?

回答

您可以使用Divider带有width(xx.dp)修饰符的函数,将内部测量值应用到其父容器。

就像是:

Row(Modifier
    .height(IntrinsicSize.Min)
    .fillMaxWidth()
    .background(Color.Yellow)) {

        Text("First Text")

        Divider(
            color = Color.Red,
            modifier = Modifier
                .fillMaxHeight()
                .width(1.dp)
        )

        Text("Second text")
}

  • @wiryadev It is not needed, for example if you have a fixed height. But if you want to obtain a layout such as reported in the answer without fixing the height you have to use it.

以上是创建垂直分隔线JetpackCompose的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>