How to create GridView using Jetpack Compose

With 1.x.y the LazyVerticalGrid composable provides experimental support for displaying items in a grid. val numbers = (0..20).toList() LazyVerticalGrid( columns = GridCells.Fixed(4) ) { items(numbers.size) { Column(horizontalAlignment = Alignment.CenterHorizontally) { Text(text = “Number”) Text(text = ” $it”,) } } } The columns = GridCells.Fixed(4) would mean that there are 4 columns 1/4 of the parent … Read more

What is the ItemDecoration for Jetpack Compose LazyColumn?

You can use the verticalArrangement parameter to add a spacing between each item using Arrangement.spacedBy(). Something like: LazyColumn( verticalArrangement = Arrangement.spacedBy(8.dp), ) { // … } The example below adds 8.dp of space in-between each item Before and after: If you want to add padding around the edges of the content you can use the … Read more

Jetpack Compose LazyColumn programmatically scroll to Item

The LazyListState supports the scroll position via the scrollToItem() function, which ‘immediately’ snaps the scroll position, animateScrollToItem() which scrolls using an animation Something like: val listState = rememberLazyListState() // Remember a CoroutineScope to be able to launch val coroutineScope = rememberCoroutineScope() LazyColumn(state = listState) { // … } Button ( onClick = { coroutineScope.launch { … Read more

How to add dividers between items in a LazyColumn Jetpack Compose?

Currently there is no built–in way to add dividers. However, you can just add a Divider in the LazyListScope. Something like: LazyColumn( verticalArrangement = Arrangement.spacedBy(12.dp), ) { items(itemsList){ Text(“Item at $it”) Divider(color = Color.Black) } } If you do not want the last item to be followed by a Divider, you can add dividers to … Read more