在 Jetpack Compose 上用 Spacer 填充剩余 space

Filling remaining space with Spacer on Jetpack Compose

我想我可能遗漏了一些东西,有没有办法在 Compose Beta01 中实现“填充 space 的其余部分”而无需额外的 Box 元素包装 [=20] =]r?不幸的是,Spacer 没有权重修饰符。

Column(
    modifier = Modifier
        .height(120.dp)
        .fillMaxWidth()
) {
    Text(
        text = "A"
    )
    Box(
        modifier = Modifier
            .weight(1f)
    ) {
        Spacer(
            Modifier
                .fillMaxHeight()
        )
    }
    Text(
        text = "B"
    )
}

编辑:

额外的盒子根本没有必要,我只是误用了修改器系统。作为旁注,所选答案可能是实现此目标的另一种好方法。

这是你需要的吗?

Column(
    modifier = Modifier
        .height(120.dp)
        .fillMaxWidth(),
    Arrangement.SpaceBetween
) {
    Text(text = "A")
    Text(text = "B")
}

您可以将元素排列为 Space Around、Space Evenly 和 Space Between。

据我所知,Column.arrangement 均匀地应用于所有 children。

如果您只想将剩余的 space 填充到最大值,您可能需要带有 weight(1.0f) 修饰符的 Spacer

Column(
    modifier = Modifier
        .fillMaxWidth()
) {
    Text("Text A") // top aligned
    Spacer(modifier = Modifier.weight(1.0f)) // fill height with spacer
    Text("Text B") // those two Texts are bottom aligned
    Text("Text C") 
}