Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jetpack Compose - Box with scrollable content

My Composable looks as below:

fun Screen() {
    Box(modifier = Modifier.fillMaxSize()) {
        Column(
            modifier = Modifier.align(Alignment.TopCenter)
        ) {
            // Content which is pretty large in height (Scrollable)
        }
        Column(
            modifier = Modifier.align(Alignment.BottomCenter)
        ) {
            // A button (CTA for next screen)
        }
    }
}

The requirement is let the CTA stick to the bottom of the screen and the actual content be scrollable. However, as per my implementation, if the actual content gets bigger in height, it pushes the CTA off the screen.

How do I make the CTA stick to the screen?

like image 976
Chandra Sekhar Avatar asked Apr 20 '26 18:04

Chandra Sekhar


1 Answers

You can use a Column instead of a Box applying the weight modifier to the 1st nested Column.
Something like:

Column() {
    Column(
        modifier = Modifier
            .verticalScroll(rememberScrollState())
            .weight(1f)
    ) {
        // Content which is pretty large in height (Scrollable)
    }
    Column(
    ) {
        // A button (CTA for next screen)
    }
}

enter image description here

like image 185
Gabriele Mariotti Avatar answered Apr 22 '26 10:04

Gabriele Mariotti



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!