0

I want to make multiple LazyColumn scrolled simultaneously in Jetpack Compose.

But, It seems that one LazyColumn prevent other LazyColumn to be scrolled.

Below screenshots is my composable structure.

enter image description here

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MultipleLazyColumnScrollTheme {
                // A surface container using the 'background' color from the theme
                Surface(modifier = Modifier.fillMaxSize(), color = MaterialTheme.colorScheme.background) {
                    MultipleLazyColumnInColumnTest()
                }
            }
        }
    }
}

@Composable
private fun MultipleLazyColumnInColumnTest() {
    Column(
        Modifier
            .fillMaxSize()
            .verticalScroll(
                state = rememberScrollState(),
                flingBehavior = ScrollableDefaults.flingBehavior()
            )
    ) {
        MultiLazyColumnRow()

        val backgroundColorList = listOf(Color.Black, Color.Red, Color.Green, Color.Blue)
        for (index in 0 until 10) {
            Spacer(
                Modifier
                    .background(color = backgroundColorList[index / 4])
                    .fillMaxWidth()
                    .height(100.dp)
            )
        }
    }
}

@Composable
fun MultiLazyColumnRow() {
    Row(
        Modifier
            .fillMaxWidth()
            .height(300.dp)
    ) {
        LazyColumn(
            Modifier
                .background(color = Color.Red.copy(alpha = 0.5f))
                .weight(1f)
        ) {
            items(count = 100) {
                Text(
                    text = it.toString()
                )
            }
        }

        LazyColumn(
            Modifier
                .background(color = Color.Green.copy(alpha = 0.5f))
                .weight(1f)
        ) {
            items(count = 100) {
                Text(text = it.toString())
            }
        }

        LazyColumn(
            Modifier
                .background(color = Color.Blue.copy(alpha = 0.5f))
                .weight(1f)
        ) {
            items(count = 100) {
                Text(text = it.toString())
            }
        }
    }
}

enter image description here

As shown in gif image,

If Red one already is in scrolling state, Whenever I scroll green LazyColumn, green LazyColumn doesn't scrolled, and Scrollable Column is scrolled.

How can I achieve my specification?

박찬준
  • 346
  • 1
  • 7

0 Answers0