gowtham 6674
10/20/2022, 12:34 PMJonas de Faria Alves
10/20/2022, 12:47 PMgowtham 6674
10/20/2022, 12:50 PMLazyVerticalGrid(
columns = GridCells.Fixed(2),
modifier = Modifier
.wrapContentSize()
.background(color = MaterialTheme.cliqColors.surface.white1),
contentPadding = PaddingValues(vertical = 12.dp, horizontal = 12.dp),
horizontalArrangement = Arrangement.spacedBy(12.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
items(3){
MyCard()
}
gowtham 6674
10/20/2022, 12:51 PMJonas de Faria Alves
10/20/2022, 12:55 PMspan
is an argument of items()
. It's available to any usages of LazyVerticalGrid
.Jonas de Faria Alves
10/20/2022, 12:57 PMgowtham 6674
10/20/2022, 1:02 PMAlbert Chang
10/20/2022, 1:31 PMhorizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterHorizontally)
?Stylianos Gakis
10/20/2022, 2:31 PMAlbert Chang
10/20/2022, 2:48 PMLazyVerticalGrid
in 1.2.0.Stylianos Gakis
10/20/2022, 2:55 PMgowtham 6674
10/20/2022, 3:04 PMhorizontalArrangement
as you said. still it shows the last element at the start of the grid. this is what i tried
LazyVerticalGrid(
columns = GridCells.Fixed(2),
modifier = Modifier
.wrapContentSize(),
horizontalArrangement = Arrangement.spacedBy(12.dp, Alignment.CenterHorizontally),
verticalArrangement = Arrangement.spacedBy(12.dp),
) {
items(3) {
Text("Hello")
}
}
gowtham 6674
10/20/2022, 3:21 PMvar size = DeviceConfig.deviceWidth.pxTodp()
LazyVerticalGrid(
columns = GridCells.Fixed(2),
modifier = Modifier
.wrapContentSize(),
) {
items(3, span = {
GridItemSpan(it)
}) {
// last item check
if (it == 2) {
Text("Hello", modifier =
Modifier.padding(horizontal = (size / 4).dp)
.background(color= Color.Red))
} else {
Text("Hello", modifier = Modifier.background(color= Color.Red))
}
}
} }
gowtham 6674
10/20/2022, 3:23 PMgowtham 6674
10/20/2022, 3:24 PMJonas de Faria Alves
10/20/2022, 3:55 PMgowtham 6674
10/26/2022, 7:00 AMvar size = DeviceConfig.deviceWidth.pxTodp()
LazyVerticalGrid(
columns = GridCells.Fixed(2),
modifier = Modifier
.wrapContentSize(),
) {
items(list.size, span = {
if(list.size % 2 != 0){
val value= if(list.lastIndex==it) 2 else 1
GridItemSpan(value)
}else {
GridItemSpan(1)
}
}) {
// last item check
if (list.lastIndex== it && list.size%2!=0) {
Text("Hello", modifier =
Modifier.padding(horizontal = (size / 4).dp)
.background(color= Color.Red))
} else {
Text("Hello", modifier = Modifier.background(color= Color.Red))
}
}
} }
updated answer. i made some changes in griditem span;