我的这一行有两个按钮和一个分隔线。
我设置了权重,以便按钮可以具有相同的宽度。
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)
属性设置为 Row,它就会消失。我不想设置任何硬编码高度,我只是希望该行具有其“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)
)
}
关于android - 在 Jetpack Compose 中将高度设置为 Row 相当于 xml 中的wrap_content,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69901020/