Lukasz Kalnik
06/26/2025, 12:11 PMSome street 1, 10000 München / Altstadt-NordI want to display it in one line, if it fits. However when it doesn't fit, I want that it breaks at the first comma, so that e.g. the zip code is not in the "street" line, and separate from the city line. I don't want to use non-breaking spaces, because then if the zip code/city part is also longer than one line, it gets broken in the middle of the words.
Lukasz Kalnik
06/26/2025, 12:12 PMMiSikora
06/26/2025, 12:15 PMLukasz Kalnik
06/26/2025, 12:16 PMLukasz Kalnik
06/26/2025, 12:49 PMval textMeasurer = rememberTextMeasurer()
val lineCount = textMeasurer.measure(
text = formattedAddress,
style = MaterialTheme.typography.bodyLarge,
).lineCount
Lukasz Kalnik
06/26/2025, 12:54 PMtextMeasurer.measure()
also needs constraints from the layout.dorche
06/26/2025, 1:09 PMLukasz Kalnik
06/26/2025, 1:10 PMonGloballyPositioned()
but it also returns infinity, I guess it's too earlydorche
06/26/2025, 1:13 PMBoxWithConstraints
however beware that this uses SubcomposeLayout so there's a cost to itMiSikora
06/26/2025, 1:13 PMBoxWithConstraints
. BoxWithConstraintsScope
has constraints
property available.MiSikora
06/26/2025, 1:14 PMMiSikora
06/26/2025, 1:14 PMdorche
06/26/2025, 1:16 PMLukasz Kalnik
06/26/2025, 1:17 PMMiSikora
06/26/2025, 1:18 PMMiSikora
06/26/2025, 1:18 PMLukasz Kalnik
06/26/2025, 1:26 PMonGloballyPositioned()
started delivering the correct width.Lukasz Kalnik
06/26/2025, 1:44 PMonGloballyPositioned()
not working was an Android Studio preview problem.