Albert Francis
08/03/2021, 8:59 AMmaxLines = 1
, and overflow = TextOverflow.Ellipsis
so it can be like. "Lorem ipsum ..." ⬆️
but if i change the overflow
to Ellipsis
the text takes the whole row and it becomes ->
"Lorem ipsum ..." without the icon
i tried inlineContent
also but that simple thing i couldn't achive anyone has idea?Daniel Weidensdörfer
08/03/2021, 9:20 AMweight(...)
modifier for the text and icon.Albert Francis
08/03/2021, 9:31 AMCsaba Szugyiczki
08/03/2021, 9:37 AMWhen fill is true, the element will be forced to occupy the whole width allocated to it. Otherwise, the element is allowed to be smaller - this will result in Row being smaller, as the unused allocated width will not be redistributed to other siblings.
Daniel Weidensdörfer
08/03/2021, 9:50 AMweight(...)
. Since theres a bit of calculation needed to align the icon perfectly on the right side of the row, I actually hope there's a simpler solution.
val screenWidth = LocalContext.current.resources.displayMetrics.widthPixels.toFloat()
val iconSize = with(LocalDensity.current) { 24.dp.toPx() }
val buttonTextRatio = iconSize/screenWidth
Row(modifier = Modifier.fillMaxWidth()) {
Text(
modifier = Modifier.weight(1-buttonTextRatio, fill = false),
text = "hallo",
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
Icon(
modifier = Modifier.weight(buttonTextRatio),
painter = painterResource(id = R.drawable.ic_baseline_cached_24),
contentDescription = null
)
}
Albert Francis
08/03/2021, 10:00 AMtext(weight=1,fill=false)
and worked like charm.