I have the below 4 strings to be aligned side by side in a FlowRow
. This is the code I have. I am not sure why even though there is some space in each line, text justification is not happening. I do not want any space after any of the lines. I want everything to be aligned with text justification.
In the following image as you see after 1st line it has some additional space which could have been taken by 2nd string and used '-' at the end.

@OptIn(ExperimentalLayoutApi::class)
@Preview
@Composable
fun JustifiedFlowRowExample() {
val items = listOf(
"This part will have an icon and text.",
"Another example of a lengthy text.",
"Short text.",
"A very long piece of text that will wrap to the next line."
)
FlowRow {
items.forEach { item ->
JustifiedText(item)
}
}
}
@Composable
fun JustifiedText(text: String) {
Row(
modifier = Modifier.padding(4.dp),
verticalAlignment = Alignment.CenterVertically
) {
Text(
text = buildAnnotatedString {
withStyle(style = SpanStyle()) {
append(text)
}
},
style = TextStyle(
textIndent = TextIndent(firstLine = 0.5.em),
),
overflow = TextOverflow.Ellipsis,
textAlign = TextAlign.Justify,
modifier = Modifier
.wrapContentWidth()
.wrapContentSize(align = Alignment.Center)
)
}
}
Is there any other way where in I can solve this problem? We can consider this Row
to include Icons
and text. For simplification i have mentioned only strings.