How to individually/separately align child composables inside a Row?
Asked Answered
O

1

20

I'm new in jetpack compose and I'm trying to do a simple thing that I can't achieve it.

That I want to do is in the same row align one component, in this case a surface, at the start and the other one, the column, at the end of the row.

How can get this?

I'm trying this but it doesn't work:

Row(Modifier.padding(top = 24.dp)
        .fillMaxWidth()) {
        Surface(
            modifier = Modifier.size(70.dp),
            shape = RectangleShape,
            color = MaterialTheme.colors.onSurface.copy(alpha = 0.2f)
        ) {
            // Image goes here
        }

        Column(modifier = Modifier.size(70.dp)) {
            Text("Total",
                fontSize = 12.sp,
                color = AppGreyDark,
                modifier = Modifier.padding(end = 16.dp))

            Text("12,99 €",
                fontSize = 18.sp,
                color = AppBlackDark,
                modifier = Modifier.padding(top = 4.dp))
        }
    }
Orme answered 6/8, 2021 at 7:33 Comment(0)
C
24

You can apply in the Row the Arrangement.SpaceBetween.

Row(
    modifier = Modifier
      .padding(top = 24.dp)
      .fillMaxWidth(),
    horizontalArrangement  =  Arrangement.SpaceBetween) {
       Surface()
       Column()
}

enter image description here

Chandlery answered 6/8, 2021 at 7:37 Comment(4)
Won't work if the surface is wide enough to reach and overflow the column.Peashooter
if I keep Surface gone, Column is coming to start place. how can I make Column not move from End alignmentColostomy
what if surface width is too big? (for example it's Text instead of Surface and has long text), how to align it before Column without using Constraints?Jarred
@MohdQasim You hide the Surface left component based on some condition, right? use the same condition to set the horizontalArrangement prop value horizontalArrangement = if (someCondition) Arrangement.SpaceBetween else Arrangement.EndZecchino

© 2022 - 2024 — McMap. All rights reserved.