Android Question height = -2 (WRAP_CONTENT), but what is real height value ?

peacemaker

Expert
Licensed User
Longtime User
HI, All

It's good code, for autoadjusting the label size (important that the text must be set _after_ height = -2).
But when real text height is very big (loooong multiline text) - we must limit the view height, to fit the activity interface.
After height = -2 - this value is stored and returned back, if to read the height.
How to get the real view size after such adjustment ? Actually, it's needed a sub to adjust the height, using the max limit, but if text is shorter - view's height should be smaller...
 

peacemaker

Expert
Licensed User
Longtime User
Seems, solved :)

B4X:
Sub Adjust_Height(v As EditText, maxlimit As Int)
    Dim Calc As Int = su.MeasureMultilineTextHeight(v, v.Text)
    If Calc > maxlimit Then
        v.Height = maxlimit
    Else
        v.SetLayout(v.Left, v.Top, v.Width, -2)
    End If
    v.Text = v.Text
End Sub
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Why, Erel ?
Seems, .MeasureMultilineTextHeight returns another result to be correct
 
Upvote 0
Top