简体   繁体   中英

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?

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)
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM