gpt4 book ai didi

android - Jetpack 撰写 : How to make two columns equals height

转载 作者:行者123 更新时间:2023-12-03 07:55:40 24 4
gpt4 key购买 nike

其中一行两列,左列有两个子行,右列有子行。

enter image description here

这是我的代码:

@Preview(showBackground = true)
@Composable
fun TwoColumns() {
Row {
BottomLeftLetterKey(columns = 2, rows = 2, Color.Blue)
Spacer(modifier = Modifier.weight(1f))
BottomLeftLetterKey(columns = 3, rows = 3, Color.Cyan)
}
}

@Composable
fun BottomLeftLetterKey(columns: Int, rows: Int, color: Color) {
Column(modifier = Modifier.background(color)) {
repeat(columns) {
Row {
repeat(rows) {
ElevatedButton(onClick = { /*TODO*/ },
shape = RoundedCornerShape(4.dp),
colors = ButtonDefaults.elevatedButtonColors(containerColor = Color.Green, contentColor = Color.Red),
contentPadding = PaddingValues(0.dp)
) {
Text(text = "2")
}
}
}
}
}
}

我希望两列高度相同。即蓝色柱应与青色柱高度相同。

我尝试设置:Column(modifier = Modifier.background(color).fillMaxHeight())

那么我想要的高度太高了。

enter image description here

有什么建议吗?谢谢!

编辑

modifier = modifier.height(IntrinsicSize.Min/Max) 是正确的方向。但困惑 MinMax 哪个选项是正确的?我试过了,效果是一样的。

来自doc :

The Row composable's minIntrinsicHeight will be the maximum minIntrinsicHeight of its children.

似乎 IntrinsicSize.Min 是正确的,而不是 IntrinsicSize.Max

最佳答案

您必须将 Modifier.height(IntrinsicSize.Min) 应用于 Row,并将 fillMaxHeight() 修饰符应用于

Row(
modifier = Modifier.height(IntrinsicSize.Min),
horizontalArrangement = Arrangement.SpaceBetween
) {
BottomLeftLetterKey(columns = 2, rows = 2, Color.Blue)
BottomLeftLetterKey(columns = 3, rows = 3, Color.Cyan)
}


@Composable
fun BottomLeftLetterKey(columns: Int, rows: Int, color: Color) {
Column(modifier = Modifier
.fillMaxHeight() //<--- fill max height
.background(color)
) {
//....
}
}

enter image description here

关于android - Jetpack 撰写 : How to make two columns equals height,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76089598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com