1

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?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
Ralf Wickum
  • 2,850
  • 9
  • 55
  • 103

1 Answers1

0

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

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
  • Thanks. `Modifier.fillMaxHeight()` helped for 1. But `Modifier.padding(xxx).fillMaxWidth()` had no effect for 2. – Ralf Wickum Jan 11 '23 at 18:26
  • I splitted my previous question into 2 questions and I accept Modifier.fillMaxHeight() as an answer for this one. My other problem is now here: https://stackoverflow.com/questions/75098208/padding-for-text-within-column-not-working – Ralf Wickum Jan 12 '23 at 14:56