列内的 fillMaxSize 优先级不清楚
fillMaxSize priority inside Column unclear
我需要做的是一个固定大小的盒子,在第一个盒子下面再放一个,它会填满左边 space。我有以下代码:
Column {
Box(
modifier = Modifier
.background(Color.Red)
.fillMaxSize()
)
Box(
contentAlignment = Center,
modifier = Modifier
.background(Color.Blue)
.height(50.dp)
.fillMaxWidth()
) {
Text(
"hello",
color = Color.White
)
}
}
出于某种原因,底部框在列边界下只有一半大小,如果我删除严格 .height(50.dp)
,它就会完全消失。我尝试过了
使用 .wrapContentHeight()
解决第二个问题,但运气不佳 - 看起来像顶部框的 fillMaxSize()
使其大小等于 Column
,这就是为什么它将底部的一部分向下推。我希望它能填充计算出其他列子项大小后剩下的大小——我是不是遗漏了什么?
如果我改变盒子的顺序,它会按预期工作,但我需要底部的大小固定
在这种情况下,应在视图上使用 weight
修饰符而不是 fillMaxSize
(weight
已经默认填充最大尺寸),在这种情况下,它将被测量其他意见后:
The parent will divide the vertical space remaining after measuring unweighted child elements and distribute it according to this weight.
Column {
Box(
modifier = Modifier
.background(Color.Red)
.weight(1f)
)
Box(
contentAlignment = Center,
modifier = Modifier
.background(Color.Blue)
.fillMaxWidth()
) {
Text(
"hello",
color = Color.White
)
}
}
我需要做的是一个固定大小的盒子,在第一个盒子下面再放一个,它会填满左边 space。我有以下代码:
Column {
Box(
modifier = Modifier
.background(Color.Red)
.fillMaxSize()
)
Box(
contentAlignment = Center,
modifier = Modifier
.background(Color.Blue)
.height(50.dp)
.fillMaxWidth()
) {
Text(
"hello",
color = Color.White
)
}
}
出于某种原因,底部框在列边界下只有一半大小,如果我删除严格 .height(50.dp)
,它就会完全消失。我尝试过了
使用 .wrapContentHeight()
解决第二个问题,但运气不佳 - 看起来像顶部框的 fillMaxSize()
使其大小等于 Column
,这就是为什么它将底部的一部分向下推。我希望它能填充计算出其他列子项大小后剩下的大小——我是不是遗漏了什么?
如果我改变盒子的顺序,它会按预期工作,但我需要底部的大小固定
在这种情况下,应在视图上使用 weight
修饰符而不是 fillMaxSize
(weight
已经默认填充最大尺寸),在这种情况下,它将被测量其他意见后:
The parent will divide the vertical space remaining after measuring unweighted child elements and distribute it according to this weight.
Column {
Box(
modifier = Modifier
.background(Color.Red)
.weight(1f)
)
Box(
contentAlignment = Center,
modifier = Modifier
.background(Color.Blue)
.fillMaxWidth()
) {
Text(
"hello",
color = Color.White
)
}
}