我的问题与此有关:How to achieve this layout in Jetpack Compose
我有这个代码:
@Composable
fun TestUi() {
Row {
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.background(color = Color.Yellow)
.fillMaxHeight()
) {
CircularProgressIndicator()
}
Image(imageVector = vectorResource(id = R.drawable.ic_launcher_background))
}
}
我希望得到这个:
但我得到的是这个:
如何让 Box 填充所有可用高度而不影响 Row 的高度?
我知道我可以使用 ConstraintLayout 来解决这个问题,但对于这样一个简单的用例来说似乎太多了。
最佳答案
这对我有用 Modifier.height(IntrinsicSize.Min)
@Composable
fun content() {
return Row(
modifier = Modifier
.height(IntrinsicSize.Min)
) {
Box(
modifier = Modifier
.width(8.dp)
.fillMaxHeight()
.background(Color.Red)
)
Column {
Text("Hello")
Text("World")
}
}
}
来源:https://www.rockandnull.com/jetpack-compose-fillmaxheight-fillmaxwidth/
关于android-jetpack-compose - 行内的 fillMaxHeight(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65702164/