Android Question Text Size Scaling

ducphu

Active Member
Licensed User
Longtime User
Hi all,

I already know that in designer, we can use AutoScaleAll to scale all the button's, label's... text size. However, I have an array of button which I add by code, I can NOT use AutoScaleAll. I come through some formula but not sure which one is the most appropriate. 2 formulas I use are:

B4X:
Dim RealInches, RealScale As Double
    Dim BaseInches, BaseScale As Double
    Dim Ratio As Double
    RealInches = GetDeviceLayoutValues.ApproximateScreenSize
    RealScale = GetDeviceLayoutValues.Scale
    BaseInches = 4.33 'My test device screen size
    BaseScale = 3 'My test device scale factor
    Ratio = RealInches/BaseInches * Sqrt(RealScale/BaseScale)
    Return Ratio

And

B4X:
Dim scale As Double
    Dim delta As Double = ((100%x + 100%y) / (640dip + 360dip) - 1)
    Dim rate As Double = 0.5 'value between 0 to 1.
    scale = 1 + rate * delta
    Return scale

When I test using my Xperia Z 1080 x 1920 441 ppi scale 3, using both formula, the text seems to be fine
When I test using my friend's Xiaomi Mi Note 1080 x 1920 386 ppi scale unknown, using 2nd formula, the text seems too big

Can anyone help me? Thanks.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…