Android Question Scale TextSize

angel_

Well-Known Member
Licensed User
I have a label that changes dimension in realtime, like this:

B4X:
factor = 1.1
label1.Height = Round(factor * label1.Height)
label1.Width = Round(factor * label1.Width)
label1.TextSize = ??

How can I scale TextSize?
 

Brian Dean

Active Member
Licensed User
Longtime User
How about using StringUtils.MeasureTextHeight? In reverse? The following works after a fashion, but needs some polishing.
B4X:
Sub label1_Click
    label1.Height = Round(factor * label1.Height)
    label1.Width = Round(factor * label1.Width)
    Dim h As Int = label1.Height
    Do While (su.MeasureMultilineTextHeight(label1, label1.Text) < h)
        label1.TextSize = label1.TextSize + 1
    Loop   
End Sub
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
How can I scale TextSize?
Here is a link to a code snippet that auto sizes the text based on the view. It can be applied to your situation and may be what you want. I tested it. I can post my code.
 
Upvote 0

angel_

Well-Known Member
Licensed User
Both solutions work fine. I like the first one but is there a more direct way and avoid the loop?
 

Attachments

  • EscalaView.zip
    9.6 KB · Views: 88
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I like the first one but is there a more direct way and avoid the loop?

You may be right, but there are many views and I would like it to work as quickly as possible
So why not use Erel's solution, which simply performs an API call? 😳

The only reason may be that it will only work with Android apps.
 
Upvote 0
Top