1

The composable is

@Preview(showBackground = true, fontScale = 2f)
@Composable
fun Test(){
    Row(modifier = Modifier.fillMaxWidth(), verticalAlignment = Alignment.CenterVertically) {
        Text(modifier = Modifier.weight(1f), text = "asjd hasjdh asjdh aksjdhaskdj haskdj")
        Icon(
            modifier = Modifier
                .padding(start = 4.dp)
                .size(16.dp),
            painter = painterResource(id = R.drawable.ic_trolley_check_circle),
            tint = MaterialTheme.textColor.success,
            contentDescription = null,
        )
    }
}

And the outcome is

enter image description here

is it possible to keep the tick where the text ended. i know the Text composable has taken the whole space. I tried weight(1f, false) as well.

Thanks

sadat
  • 4,004
  • 2
  • 29
  • 49
  • Does this answer your question? [How to show ellipsis (three dots) at the end of a Text line in Android Jetpack Compose?](https://stackoverflow.com/questions/65736375/how-to-show-ellipsis-three-dots-at-the-end-of-a-text-line-in-android-jetpack-c) – Ivan Shafran Feb 21 '23 at 23:34
  • I dont want to discard any text. I just want to put the tick where the text ended (visually) – sadat Feb 21 '23 at 23:49
  • `Modifier.weight(1f, fill = false)` is correct here, but it doesn't work because of multiline text bug. So add `fill = false` and check out [this answer](https://stackoverflow.com/a/69947555/3585796) – Phil Dukhov Feb 21 '23 at 23:50
  • if you dont want the space between text and Icon then remove modifier.weight(1f) – Dilshad Feb 22 '23 at 02:52
  • in that case, the icon wont show @Dilshad – sadat Feb 22 '23 at 02:57
  • i tried it and it worked check : https://pasteboard.co/uArQ4AwsLOpB.png @sadat – Dilshad Feb 22 '23 at 03:18
  • try more text or bigger fontscale @Dilshad – sadat Feb 22 '23 at 04:40
  • 1
    Can you add a screen of the expected result? – Gabriele Mariotti Feb 22 '23 at 10:27

1 Answers1

-1

You can use FlowRow for this purpose.

FlowRow {
    Text()
    Icon()
}

With this FlowRow, when an item width is bigger than space that is left in a row, it goes to next row.

Hence you don't need weight(1f) here.

mrzbn
  • 497
  • 1
  • 3
  • 15