Android Question Autoscale a label by self-made code


Active Member
Licensed User
Dear members,

I have a question. It would be very nice if you could help me! There is a Autoscale module on but I can't use this in some modules. Also it would be useful to have a second code by hand...
My problem is that sometimes the text is too big and sometimes the textsize is 1, so that you don't see anything...

Now here is my code: (#1)
Sub scalelbl1
    Dim bmp As Bitmap
    Dim size As Float
    For size = 2 To 80
        If CheckSize(size) Then 
    size = size - 0.5
    If CheckSize(size) Then size = size - 0.5
    Label1.TextSize = size
End Sub

Sub CheckSize(size As Float) As Boolean
        Return cv.MeasureStringWidth(Label1.Text, Label1.Typeface, size) > Label1.Width OR _
            suu.MeasureMultilineTextHeight(Label1, Label1.Text) > Label1.Height
End Sub

Do Until cv.MeasureStringWidth("X", Typeface.DEFAULT, size) < 45dip AND suu.MeasureMultilineTextHeight(labelex, "X") < 45dip OR size = 1
    size = size -0.5
    labelex.TextSize = size
All code subs get called every time when the text changes
I made a example project:
Why it's on Dropbox? So I can update the file if needed!

It would be great if you could help me solving the mistake in my code!
Thanks for reading this entry!

Yours sincerely,


Active Member
Licensed User
There is a missing keyword after Then.
Probably Exit.

Other than that the code looks correct.
Thank you for your answer. I forgot that word in my Code example. If you look in my example project you see it is in... but it does work neither :/

If needed I can make a video how it looks on my phone


Licensed User
This code works:
Sub SetTextSize(lbl As Label)
    lbl.TextSize = 50
    Do Until cv.MeasureStringWidth(lbl.Text, lbl.Typeface, lbl.TextSize) < lbl.Width AND stu.MeasureMultilineTextHeight(lbl, lbl.Text) < lbl.Height OR lbl.TextSize <= 1
    lbl.TextSize = lbl.TextSize - 0.5
End Sub


Active Member
Licensed User
hey klaus!

Thank you!!!
On the first view it looks very good! I will test it! Thank you so much!

Best regards