Here is my code:
Row {
Text(
text = text1,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
Spacer(modifier = Modifier.width(2.dp))
Text(
text = text2,
maxLines = 1,
)
}
The text2's length is short (but not specical width) while text1's length may be long or short. I want text2 always visible and text1 shows ellipsis when it is long.
The Modifier.weight(1F)
can't meet my requirement because text1 will
fill up the remaining space and text2 always at the end of Row
. Is there any way to do that?
CodePudding user response:
You can use the parameter fill = false
, if you don't want weigth
to fill the remaining space.
Row {
Text(
text = text1,
maxLines = 1,
overflow = TextOverflow.Ellipsis,
modifier = Modifier.weight(weight = 1f, fill = false)
)
Spacer(modifier = Modifier.width(2.dp))
Text(
text = text2,
maxLines = 1,
)
}
In this way, when text1
is short it will take the minimum space it needs, and when text1
is long it will fill as much as it can. In both cases text2
will still take its own space and remain visible.