I am trying to get my Lazy Vertical Grid to be working the way I have it in the non-JetpackCompose version. I have this keypad that contains buttons ranging from 0 to 9 and a clear button. The grid is 3 buttons wide, it starts with 1 to 9, the last column contains 0 and CLEAR, however the CLEAR buttons should be twice as wide as the other buttons. See this image from the non-Jetpack Compose version of my app:
这是我目前拥有的代码,请注意,我刚刚开始从事Jetpack编写工作,所以与其他XML样式相比,我的知识并不是很高.
LazyVerticalGrid(
GridCells.Fixed(3),
modifier = Modifier.fillMaxWidth()
) {
itemsIndexed(keypadBtn + listOf("0", "CLEAR")) { _, keyTxt ->
Box(
contentAlignment = Alignment.Center,
modifier = Modifier
.fillMaxWidth()
.size(width = if(keyTxt == "CLEAR") 260.dp else 120.dp, height = 80.dp)
.padding(start = 5.dp, end = 5.dp, top = 5.dp, bottom = 5.dp)
.clip(RoundedCornerShape(16.dp))
.background(if (keyTxt == "CLEAR") Color.Gray else Color.White)
.weight(if (keyTxt == "CLEAR") 2f else 1f)
.clickable {
// Handle click action here
}
) {
Text(
text = keyTxt,
color = if (keyTxt == "CLEAR") Color.White else Color.Black,
fontSize = 36.sp,
fontWeight = FontWeight.Bold
)
}
}
}