【发布时间】:2021-04-29 20:52:35
【问题描述】:
我想创建一个包含多行的 LazyColumn,每行最多包含 2 张“卡”,其中最后一行可能只包含一张卡(如果卡的数量是奇数)。我想建立一个系统来确定要创建的行数(卡数除以 2)然后根据卡数是奇数还是偶数,将行数四舍五入,然后放入 1 或 2 张卡行。
example:
5 cards = 3 total rows, 2 full rows, with the last row only having one card
4 cards = 2 total rows, 2 full rows
6 cards = 3 total rows, 3 full rows
“用尽”是指我希望系统在满足卡片数量后停止用卡片填充行。
//Fix my code pls :)
fun isOddNum(num:Int):Boolean {
return when {
num % 2 == 0 ->false
else->true}
}
@Composable
fun myColumn(Amount_of_Cards:Int){
val Amount_of_Rows = Amount_of_Cards/2
var isOdd=isOddNum(Amount_of_Cards)
LazyColumn() {
items((0..Amount_of_Rows).toList()) {
if (isOdd == true) {
RestCardVert(type = "bagel", name = "BTB", isOpen =true , address = "219 Ba", rating = 4, color = 1 )
} else {
RestCardVert(type = "bagel", name = "BTB", isOpen =true , address = "219 Ba", rating = 4, color = 1 )
RestCardVert(type = "bagel", name = "BTB", isOpen =true , address = "219 Ba", rating = 4, color = 1 )
}
}
}
}
}
【问题讨论】:
-
你有什么问题?
-
对不起,我问的是什么代码可以让我创建上面发布的列、行和卡片的配置,如果我的代码示例走在正确的轨道上,迭代我的下一步将是什么。
标签: android kotlin android-jetpack-compose