SmartToolFactory / Jetpack-Compose-Tutorials

🚀🧨📝 Series of Tutorials to learn about Jetpack Compose with subjects Material Widgets, Layout, SubcomposeLayout, custom layouts, State, custom rememberable, recomposition, LaunchedEffect, side-effects, Gesture, Animation, Navigation, Canvas, UIs like whatsapp and others.
Apache License 2.0
3.01k stars 312 forks source link

hi!i want ask your question about your reply in stackoverflow.com #20

Open yuqingweng opened 10 months ago

yuqingweng commented 10 months ago

how-to-put-a-lazyverticalgrid-inside-a-scrollable-column when item count = 500, maybe have some problems in scroll

@Preview(showBackground = true)
@Composable

private fun Test() {
    Column(
        modifier = Modifier
            .fillMaxSize()
            .verticalScroll(rememberScrollState())
    ) {
        Box(modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)
            .background(Color.Red))

        Stats(
            modifier = Modifier.heightIn(max = 1000.dp),
            stats = List(500) { it }
        )

        Box(modifier = Modifier
            .fillMaxWidth()
            .height(200.dp)
            .background(Color.Yellow))

    }
}
@Composable
fun Stats(
    modifier: Modifier = Modifier,
    stats: List<Int>
) {
    LazyVerticalGrid(
        modifier = modifier,
        columns = GridCells.Fixed(2)
    ) {

        itemsIndexed(stats) { index, item ->
            Box(
                modifier = Modifier.aspectRatio(1f),
                contentAlignment = Alignment.Center
            ) {
                Text("Item $index")
            }
        }
    }
}