Complete the code to create a vertical LazyVerticalGrid with 2 columns.
LazyVerticalGrid(columns = GridCells.Fixed([1])) { items(10) { index -> Text(text = "Item $index") } }
GridCells.Fixed() instead of inside.The GridCells.Fixed(2) creates a grid with exactly 2 columns.
Complete the code to add padding of 8.dp around each grid item.
LazyVerticalGrid(columns = GridCells.Fixed(2)) { items(5) { index -> Text(text = "Item $index", modifier = Modifier.[1](8.dp)) } }
margin which is not a Compose modifier.size which changes the size, not padding.The padding modifier adds space inside the item's boundary.
Fix the error in the code by completing the blank to specify the grid's orientation as horizontal.
LazyVerticalGrid(columns = GridCells.Fixed(3), [1] = Orientation.Horizontal) { items(6) { index -> Text(text = "Item $index") } }
direction which is not a valid parameter here.layoutDirection with orientation.The correct parameter to set grid orientation is orientation.
Fill both blanks to create a LazyVerticalGrid with 3 fixed columns and add a background color of Color.LightGray to each item.
LazyVerticalGrid(columns = GridCells.[1](3)) { items(4) { index -> Box(modifier = Modifier.background([2]).padding(8.dp)) { Text(text = "Item $index") } } }
Adaptive instead of Fixed for fixed columns.GridCells.Fixed(3) sets 3 columns. Color.LightGray sets the background color.
Fill all three blanks to create a LazyVerticalGrid with adaptive columns of minimum 100.dp width, add 12.dp padding around each item, and set the text color to Color.Black.
LazyVerticalGrid(columns = GridCells.[1](100.dp)) { items(3) { index -> Text(text = "Item $index", modifier = Modifier.padding([2]), color = [3]) } }
Fixed instead of Adaptive for adaptive columns.GridCells.Adaptive(100.dp) creates columns that adapt with minimum width 100.dp. Padding is 12.dp and text color is black.