Android Question AutoScale/AutoScaleAll in the code

b4auser1

Well-Known Member
Licensed User
Longtime User
Is there a way to apply AutoScale/AutoScaleAll for the views been created in the code?

I noticed that for the Label with TextSize=14, which I have created using Designer (320x480 variant), B4A scales (enlarges) real size of text on the device 540x960.
I managed to achieve the same physical size of text on the screen (540x960), only when set TextSize to 15.

B4X:
        Dim TB_lblTitle As Label : TB_lblTitle.Initialize("")
            TB_lblTitle.Color = Colors.Transparent
            TB_lblTitle.Gravity = Gravity.CENTER_VERTICAL + Gravity.LEFT
            TB_lblTitle.TextColor = Colors.Black
            TB_lblTitle.TextSize = 15
            pnlTB.AddView(TB_lblTitle, 1%x, 0dip, 69%x, pnlTB.Height)
In the Designer I set
TextStyle
...
Size = 14
B4X:
TB_lblTitle.Left = 1%x
TB_lblTitle.Top = 0dip
TB_lblTitle.Width = 69%x
TB_lblTitle.Height = pnlTB.Height
 

klaus

Expert
Licensed User
Longtime User
You can either :
- have a look at the AutoScale module or
- calculate the scale for the text.
The equations for scale in the DesignerScripts are:
B4X:
delta = ((100%x + 100%y) / (320dip + 430dip) - 1)
rate = 0.3 'value between 0 to 1.
scale = 1 + rate * delta
 
Upvote 0
Top