在 Jetpack Compose 中将高度设置为行等同于 xml 中的 wrap_content

Set height to Row in Jetpack Compose equivalent to wrap_content in xml

这一行有两个按钮和一个分隔线。
我已经设置了重量,所以按钮可以有相同的宽度。

Row(modifier = Modifier
    .fillMaxWidth()
    .padding(horizontal = 5.dp)
    .height(300.dp)
) {
    Button(
        stringResource(id = R.string.ha_topos_button_description),
        Modifier.weight(1f)
    )
    Divider(whichType = "vertical")
    Button(
        stringResource(id = R.string.ha_gyms_button),
        Modifier.weight(1f)
    )
}

如果我不将 .height(300.dp) 属性 设置为行,它就会消失。我不想设置任何硬编码高度,我只希望该行具有其“wrap_content”高度。
我怎样才能在 Compose 上做到这一点???

使用wrapContentHeight让行换行到内容的高度:

Row(modifier = Modifier
    .fillMaxWidth()
    .padding(horizontal = 5.dp)
    .wrapContentHeight()
) {
    Button(
        stringResource(id = R.string.ha_topos_button_description),
        Modifier.weight(1f)
    )
    Divider(whichType = "vertical")
    Button(
        stringResource(id = R.string.ha_gyms_button),
        Modifier.weight(1f)
    )
}