Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Row with two Text in Constraint fashion in Jetpack Compose

I want to include two Text in a Row where the first Text's width is upto the start of 2nd Text, like this enter image description here

I am trying Modifier weight but the result achieved is not the same. Is there a way to do it by using Row itself and not ConstraintLayout.

EDIT :

Row(modifier = Modifier.fillMaxWidth()) {
          Text(
            "Some long title abcd efgh ijkl mnop qrst uvwx yzzzzz Some long title abcd efgh ijkl mnop qrst uvwx yzzzzz",
            maxLines = 1,
            overflow = TextOverflow.Ellipsis,
            modifier = Modifier.weight(5f)
          )
          Text("View all", modifier = Modifier.weight(1f))
        }

This works, please suggest a better solution if I am missing something.

EDIT 2 : Its giving me results like this: enter image description here I want the Title to start from the beginning of Row

like image 295
Ali_Waris Avatar asked Feb 03 '26 16:02

Ali_Waris


1 Answers

You can use something like:

Row(
    modifier = Modifier.fillMaxWidth(),
    horizontalArrangement = Arrangement.SpaceBetween) {
    Text(
        "Short title",
        maxLines = 1,
        overflow = TextOverflow.Ellipsis,
        modifier = Modifier.weight(1f)
    )
    Text("View all")
}

enter image description here enter image description here

like image 183
Gabriele Mariotti Avatar answered Feb 05 '26 06:02

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!