Android Question Button text not scaling correctly

ginsh

Member
Licensed User
Longtime User
Hi,

I have tried the below code and it works fine with Samsung S5 even if I increase the font size on the phone. But when I am testing the same in Samsung S6 & S7 it is not working. The text on the buttons are not scaled correctly.

Please anyone help me out.

B4X:
Sub Process_Globals
   Dim access As Accessiblity
End Sub

Sub Globals

End Sub

Sub Activity_Create(FirstTime As Boolean)
   ResetUserFontScale(Activity)
End Sub

Sub ResetUserFontScale(p As Panel)
   For Each v As View In p
     If v Is Panel Then
       ResetUserFontScale(v)
     Else If v Is Label Then
       Dim lbl As Label = v
       lbl.TextSize = lbl.TextSize / access.GetUserFontScale
     Else If v Is Spinner Then
       Dim s As Spinner = v
       s.TextSize = s.TextSize / access.GetUserFontScale
     End If
   Next
End Sub
 

Attachments

  • S5.png
    S5.png
    232.5 KB · Views: 261
  • S6 & S7.jpg
    S6 & S7.jpg
    23 KB · Views: 265

ginsh

Member
Licensed User
Longtime User
Hi,

Find attached the simple test code. I have tested this code in S6 & S7 and the
text on the buttons are not showing completely. But works fine with Samsung s5.
 

Attachments

  • Test - scaling.zip
    421.1 KB · Views: 184
Upvote 0

Anser

Well-Known Member
Licensed User
Longtime User
For a height of 28dip you need a TextSize of 8 to get the text displayed correctly.

Is there a specific ratio or formula for this so that we could follow this as a guideline while developing app.

Regards
Anser
 
Upvote 0

An Schi

Well-Known Member
Licensed User
You can also use java object to remove the padding of the button to make more text fit in. Search the forum for button padding.
 
Upvote 0
Top