Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting something below a LazyColumn in Jetpack Compose

I would like my screen to show a scrolling list and a button below it. The button should always be visible. I tried the following, but it did does not work. The LazyColumn takes the entire screen. I want the Button to take it's space at the bottom, and then the LazyColumn has the rest of the screen.

Column(Modifier.fillMaxSize()) {
    LazyColumn {
        items(50) { i ->
            Text("Row $i", Modifier.fillMaxWidth().padding(8.dp))
        }
    }
    Button(onClick = { println("hi") }) {
        Text("Hello")
    }
}
like image 382
Rob N Avatar asked Feb 28 '21 21:02

Rob N


People also ask

What is LazyColumn in jetpack compose?

A LazyColumn is a vertically scrolling list that only composes and lays out the currently visible items. It's similar to a Recyclerview in the classic Android View system.

How do you make a scrollable column in jetpack compose?

We can make the Column scrollable by using the verticalScroll() modifier.

Does jetpack compose use views?

Jetpack Compose is designed to work with the established View-based UI approach. If you're building a new app, the best option might be to implement your entire UI with Compose.


Video Answer


1 Answers

You can apply the weight modifier to the lazyColumn:

Column(Modifier.fillMaxSize()) {
    LazyColumn(Modifier.weight(1f)) {
        items(50) { i ->
            Text("Row $i", Modifier.fillMaxWidth().padding(8.dp))
        }
    }
    Button(onClick = { println("hi") }) {
        Text("Hello")
    }
}

This is also explained in the Jetpack Compose basics codelab

like image 140
Sinner of the System Avatar answered Dec 25 '22 15:12

Sinner of the System