verticalArrangement = Arrangement.Bottom for Column not working

2k Views Asked by At

I have a Jetpack Compose composable in a column beginning with a icon, title, textbody and a pager row:

Box(modifier = Modifier
    .fillMaxSize()
    .background(color = TVTheme.colors.blue)
) {

val bigPadding = 334.dp
val smallPadding = 24.dp

    Column(
        verticalArrangement = Arrangement.Bottom,
        horizontalAlignment = Alignment.CenterHorizontally
    ) {

        Image(
            modifier = Modifier
                .requiredSize(128.dp, 17.dp),
            icon = R.drawable.calendar_a_icon
        )
        

        // title
        val title = "Lorem Ipsum Dolor Sit"
        if (title.isNotEmpty()) {
            Text(
                text = title,
                textAlign = TextAlign.Center,
                modifier = Modifier
                    .padding(top = dimensionResource(id = R.dimen.vertical), start = bigPadding, end = bigPadding),
                overflow = TextOverflow.Visible
            )
        }

        // body
        val body = "Lorem ipsum dolor sit. Lorem ipsum dolor sit. Lorem ipsum dolor sit. Lorem ipsum dolor sit."
        if (body.isNotEmpty()) {
            Text(
                text = body,
                textAlign = TextAlign.Center,
                modifier = Modifier
                    .padding(top = dimensionResource(id = R.dimen.vertical), start = bigPadding, end = bigPadding),
                overflow = TextOverflow.Visible
            )
        }

        Row(
            modifier = Modifier
                .padding(top = 44.dp, bottom = smallPadding, start = smallPadding, end = smallPadding)
                .fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceBetween
        ) {

            val text = AnnotatedString.Builder(item.skipButtonText).toAnnotatedString()

            ClickableText(
                maxLines = 1,
                text = "Skip",
                onClick = {
                    skip()
                }
            )

            Pager(
                modifier = Modifier
                    .align(Alignment.CenterVertically),
                index = currentPageIndex,
                pageNumbers = totalPages)
        }
    }
}

which produces this screen:enter image description here

The column has verticalArrangement = Arrangement.Bottom but obviously the column is not aligned to the bottom, it starts on top.

So how can I align the column to bottom as required in verticalArrangement = Arrangement.Bottom?

1

There are 1 best solutions below

2
On BEST ANSWER

The verticalArrangement = Arrangement.Bottom places children vertically such that they are as close as possible to the bottom of the main axis.

In your case you have to apply Modifier.fillMaxHeight() to the Column:

Column(
    verticalArrangement = Arrangement.Bottom,
    horizontalAlignment = Alignment.CenterHorizontally,
    modifier = Modifier.fillMaxHeight()
) {

If you want to apply a fix padding, you can use something like modifier = Modifier.padding(xxx).fillMaxWidth().

    // title
    val title = "Lorem Ipsum Dolor Sit"
    Text(
        text = title,
        textAlign = TextAlign.Center,
        modifier = Modifier,
            .padding(start = bigPadding, end = bigPadding).fillMaxWidth(),
        overflow = TextOverflow.Visible
    )

enter image description here