Android Question MeasureMultilineTextHeight vs. Label line breaking question

_marek

Member
Licensed User
Longtime User
Hello guys,
Let`s have following string:
B4X:
Dim myText As String = "ABBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" ' no spaces here

I am displaying it on a label, and I am using MeasureMultilineTextHeight to adjust label height, (something) like this:
B4X:
Dim Label1 As Label
Label1.Initialize("")
Label1.Typeface = Typeface.MONOSPACE
Label1.SingleLine = False
Label1.Text = myText
Label1.TextSize = 20
Activity.AddView(Label1, 10dip, 10dip, 200dip, 30dip)
Dim su As StringUtils
Label1.Height = su.MeasureMultilineTextHeight(Label1, Label1.Text)

Since myText is long, it is splited, as expected, across 2 lines on a label. And MeasureMultilineTextHeight returns correct height which when applied for Label1.Height, whole text is visible and Label1 has no extra height (notice a red border around the label).
1680343405825.png


However, if I modify myText by inserting space character like this:
B4X:
Dim myText As String = "A BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB" ' second character is a space

Then MeasureMultilineTextHeight returns a height which creates extra space on a Label1 (seems like for one extra line), like this:
1680343493235.png


Is this beacuse MeasureMultilineTextHeight, when evaulating myText, sees/breaks it like this?

A <= line break at a word level
BBBBBBBBBBBBBBBBBBBBBBBBB <=line break because of label width exceeded
BBBBBBBB


If so, can MeasureMultilineTextHeight be somehow setup to break the lines as Label1 does?
If no, can Label1 be configured in a way that it splits myText as MeasureMultilineTextHeight does?

The goal is to have label height set correctly, without any extra (and shortage) of a space for any sequence of characters (Label1 is expected to contain sequences of random characters, like $uemTS5& dh,-44s2C0x.?h^o etc...)

If my explanation and questions are invalid, please correct me.

Thanks.
 
Top