Android Question scale and userfontscale

sorex

Expert
Licensed User
Longtime User
Hello,

In an old game of mine I use a lot of text labels.

A player of this game told me that her eyes aren't what they use to be anymore and she increased the font size so that text messages etc are a bit better to read.
This caused that most things in the game look blown up.

The original method that I used for text size and works fine on Android & IOS is

B4X:
'---common---
Dim scale As Double

lv.TextSize=(7.5%y/scale)

This is the method that I use now and works fine aswell

B4X:
'---common---
Dim scale As Double
Dim userFontScale As Float
Dim access As Accessibility
userFontScale=access.GetUserFontScale

lv.TextSize=(7.5%y/scale)*(2-userFontScale)

for those who don't get the weird math...

the userFontScale values are like this:

small 0.85
normal 1
large 1.15
huge 1.29999
extra huge 1.30000

the (2 - [one of the above values]) give you the up/down scaling multiplier factor

so if the setting is set to extra huge (30% bigger fonts) the calculated size gets multipled by 0.70 (2-1.30) so it shrinks the size by 30%

now that this works fine from small to extra huge font sizes in the devices setting I wonder if this is the most elegant way to do this?
there's no general setting to ignore font scaling?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
This question comes up quite often. There is no general switch to ignore the user setting and it also doesn't make too much sense to ignore it as the user has likely changed this setting for a reason.

There is a sub that I wrote that compensates for this setting, for some of the views: https://www.b4x.com/android/forum/pages/results/?query=ResetUserFontScale
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
indeed, it's increased for a reason but it doesn't apply in the game as the menu text items are big already.

and as the game grid consists of labels things look bad there too.

It makes more sense in a chat app or something like that tho.

I saw your solution but I added the device scale too. that's 2 on my phone and otherwise it also looks double as big.
It was less on the original phone I created this on that's why it's there.

But in the end it could be simplified to

B4X:
'---common---
Dim scale As Double
Dim userFontScale As Double
Dim access As Accessibility
userFontScale=access.GetUserFontScale

lv.TextSize=(7.5%y/scale)/userFontScale

not sure why I didn't go for the division method from the start tho so thanks for the hint :)
 
Upvote 0
Top