https://kotlinlang.org logo
#compose
Title
# compose
m

Marcin Wisniowski

02/08/2022, 1:52 AM
I can use
maxLines = 5
on a
Text
to limit it to 5 lines, but how do I make it always take the space of 5 lines, even if there is less text? I'm looking for a
minLines = 5
, if there was one.
4
z

Zun

02/08/2022, 9:29 AM
Also looking for an answer! I used a hack by appending X amount of \n to it so it always fills the space
m

Marcin Wisniowski

02/08/2022, 10:59 AM
I also ended up using a hack with
\n
. Would be nice to have a proper solution.
f

Filip Wiesner

02/08/2022, 11:59 AM
Not sure about
TextField
but in regular
Text
you can use lineHeight of your font to specify height of the text:
Copy code
maxLines = NumberOfLines,
modifier = modifier.height( // for min lines
    with(LocalDensity.current) { MyTextStyle.lineHeight.toDp() * NumberOfLines }
)
It still feels like a hack but less than inserting
\n
at the end of string 😄
w

wintersoldier

02/08/2022, 12:10 PM
@Marcin Wisniowski You can define a certain height in that case.
m

Marcin Wisniowski

02/08/2022, 1:01 PM
Yes but I don't know what's the height, because it depends on the text style, which may not be fixed.
Using line height seems better!