-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Yasutaka.Kawamoto
committed
Nov 10, 2023
1 parent
4f5c1db
commit 37b00a4
Showing
3 changed files
with
160 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
app/src/main/java/net/kwmt27/jetpackcomposeplayground/list/GridCustomItem.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package net.kwmt27.jetpackcomposeplayground.list | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.foundation.border | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.height | ||
import androidx.compose.foundation.layout.wrapContentSize | ||
import androidx.compose.foundation.lazy.grid.GridCells | ||
import androidx.compose.foundation.lazy.grid.GridItemSpan | ||
import androidx.compose.foundation.lazy.grid.LazyVerticalGrid | ||
import androidx.compose.foundation.lazy.grid.items | ||
import androidx.compose.material.Text | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.compose.ui.unit.dp | ||
import net.kwmt27.jetpackcomposeplayground.ui.theme.JetpackComposePlayGroundTheme | ||
|
||
@Composable | ||
fun GridCustomItem() { | ||
val sections = (0 until 25).toList().chunked(5) | ||
LazyVerticalGrid( | ||
columns = GridCells.Fixed(3), | ||
horizontalArrangement = Arrangement.spacedBy(16.dp), | ||
verticalArrangement = Arrangement.spacedBy(16.dp) | ||
) { | ||
sections.forEachIndexed { index, items -> | ||
item(span = { GridItemSpan(maxLineSpan) }) { | ||
Text( | ||
"This is section $index", | ||
Modifier | ||
.border(1.dp, Color.Gray) | ||
.height(80.dp) | ||
.wrapContentSize() | ||
) | ||
} | ||
items( | ||
items, | ||
// not required as it is the default | ||
span = { GridItemSpan(1) } | ||
) { | ||
Text( | ||
"Item $it", | ||
Modifier | ||
.border(1.dp, Color.Blue) | ||
.height(80.dp) | ||
.wrapContentSize() | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
fun PreviewGridCustomItem() { | ||
JetpackComposePlayGroundTheme { | ||
GridCustomItem() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters