androidkotlinandroid-jetpack-composeandroid-jetpack

How to force a LazyColumn to have the max height rather than using scroll?


In my MainActivity I create this screen:

setContent {
    MyTheme {
        Surface(
            modifier = Modifier.fillMaxSize()
        ) {
            MainScreen()
        }
    }
}

That looks like this:

Scaffold(
    topBar = {/* ... */},
    content = { innerPadding ->
        Column(
            modifier = Modifier.padding(innerPadding).fillMaxSize()
        ) {
            Column() {
                Text("Info1")
                Text("Info2")
            }
            LazyColumn(
                modifier = Modifier.fillMaxSize()
            ) {
                items(users) { user ->
                    Text(user.ane)
                }
            }
        }
    }
)

The problem is that when I have multiple user names displayed in the LazyColumn, I get a scroll. What I want is when I have multiple user names, to expand the list so I can scroll the entire MainScreen and not only the content of the LazyColumn. How to solve this?


Solution

  • You can move whatever should be scrolled with the LazyColumn inside the LazyColumn as well:

    LazyColumn(
        modifier = Modifier.fillMaxSize()
    ) {
        item {
            Column {
                Text("Info1")
                Text("Info2")
            }
        }
    
        items(users) { user ->
            Text(user.ane)
        }
    }
    

    If you use keys for your items you should specify one too for this new item.