Created
January 15, 2024 07:16
-
-
Save Starchild13/8075beb1f9b788f59c8d7aad0491c43e to your computer and use it in GitHub Desktop.
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
// Annotation to use experimental API for Foundation layout | |
@OptIn(ExperimentalFoundationApi::class) | |
@Composable | |
fun GridExample() { | |
// Creating a LazyVerticalStaggeredGrid with fixed 3 columns | |
LazyVerticalStaggeredGrid( | |
columns = StaggeredGridCells.Fixed(3), | |
modifier = Modifier.padding(8.dp) // Adding padding around the entire grid | |
) { | |
// Iterating over items returned by getItems() function | |
items(getItems()) { drawable -> | |
// Displaying each item as an Image | |
Image( | |
painter = painterResource(id = drawable), | |
contentDescription = "", | |
modifier = Modifier.padding(4.dp) // Adding padding around each image | |
) | |
} | |
} | |
} | |
// Function returning a list of drawable resource IDs | |
fun getItems(): List<Int> { | |
return listOf( | |
// List of drawable resources (images) | |
R.drawable.garfield1, R.drawable.garfield2, R.drawable.garfield3, | |
R.drawable.garfield4, R.drawable.garfield5, R.drawable.garfield6, | |
R.drawable.garfield10, R.drawable.garfield11, R.drawable.garfield16, | |
R.drawable.garfield7, R.drawable.garfield18, R.drawable.garfield1, | |
R.drawable.garfield16, R.drawable.garfield9 | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment