Android Question DoEvents alternative for updated views

Status
Not open for further replies.

bernardR

Member
Licensed User
Longtime User
Hello,

I use this code for adjust fontsize of label
B4X:
Sub sizeH(txt As String, fontsize As Float) as int
'calcule la hauteur d'un texte
Dim h As Int
    Dim r As Reflector

    Dim lblTest1 As Label
    lblTest1.Initialize("")
    lblTest1.Color=Colors.Transparent
    lblTest1.TextColor=Colors.Transparent
    lblTest1.Text=txt
    r.Target=lblTest1
    Activity.AddView(lblTest1,0,0,-2,-2)
    lblTest1.TextSize=fontsize
    DoEvents    ' needed to update the properties
    'w=r.RunMethod("getWidth")
    h=r.RunMethod("getHeight")
Log("sizeH="&h)
    lblTest1.RemoveView
    Return h
End Sub



How replace DoEvents ?
Thanks
 
Last edited:

klaus

Expert
Licensed User
Longtime User
I would do it that way:
B4X:
Private Sub SetMaxTextSize(lbl As Label)
    Private stu As StringUtils
    Private h As Float
    Private i As Int
   
    For i = 45 To 20 Step -1
        lbl.TextSize = i
        h = stu.MeasureMultilineTextHeight(lbl, lbl.Text)
        If h <= lbl.Height Then Exit
    Next
End Sub
And the calling line:
B4X:
SetMaxTextSize(lblMain)
No need to add and remove a view.
 
Upvote 0
Status
Not open for further replies.
Top