Android Question Big drawing diferences between devices

eelias

Active Member
Licensed User
Longtime User
I use a Samsung Tab E 9.6 as my main dev testing device, and a Motorola cellphone device

On both devices all design based on anchors and layout scripts.

And the same app works with many other devices just fine, scalling perfectly.

Now I am working with 2 new devices with problems in scaling.

for example, on Samsung a button with 100dip x 100dip on this new device shows up like 50% bigger.

If the problem was in buttons or some details I could handle, but everything is bigger than should be.

If I change the sizes of buttons and other stuff it starting looks OK, but I cant just change everything for this device only.

Using LayoutValues I got: 1208 x 800, scale = 1.5 (240 dpi)

GetDevicePhisicalSize give me back: 6.0370154

My reference device (Samsung tablet) LayoutValues are : 1280 x 800, scale = 1.0 (160 dpi)
and GetDevicePhisicalSize give me back: 9.433981

what is pretty close to the 9.6 from the devices specs.

SO, is there is a way to "teatch" B4A that the device is lying about its size ? I have a WinTech POS either that happens the same problem, it advertises as 14 inch and the software get it like 10 inch.
 

William Lancee

Well-Known Member
Licensed User
Longtime User
Device sizes are published as the diagonal size. Your 14 inch tablet should have a diagonal of 14 inches.
My device is published as a 10 inch tablet but the diagonal actually measures 9 5/8 inches.
The following code reports that pretty accurately.

In my case the dots per inch computed from "160 * GetDeviceLayoutValues.Scale" is reported as 320 instead of the actual which is 275.4
The density independent pixel (dip) is rounded from 275.4/160=1.72 to 2, which make dips bigger then they should be. In your case about 50% bigger.


B4X:
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    r.Target = r.RunMethod("getDisplayMetrics")
    Log(r.GetField("xdpi"))
    Log(r.GetField("ydpi"))
    Dim xw As Float = GetDeviceLayoutValues.Width/r.GetField("xdpi")
    Dim xh As Float = GetDeviceLayoutValues.Height/r.GetField("ydpi")
    Log(xw & TAB & xh & TAB & Sqrt(xw * xw + xh * xh))  'Log: 5.787403583526611    7.716537952423096    9.645672680785086
 
Last edited:
Upvote 0

eelias

Active Member
Licensed User
Longtime User
Device sizes are published as the diagonal size. Your 14 inch tablet should have a diagonal of 14 inches.
My device is published as a 10 inch tablet but the diagonal actually measures 9 5/8 inches.
The following code reports that pretty accurately.

In my case the dots per inch computed from "160 * GetDeviceLayoutValues.Scale" is reported as 320 instead of the actual which is 275.4
The density independent pixel (dip) is rounded from 275.4/160=1.72 to 2, which make dips bigger then they should be. In your case about 50% bigger.


B4X:
    Dim r As Reflector
    r.Target = r.GetContext
    r.Target = r.RunMethod("getResources")
    r.Target = r.RunMethod("getDisplayMetrics")
    Log(r.GetField("xdpi"))
    Log(r.GetField("ydpi"))
    Dim xw As Float = GetDeviceLayoutValues.Width/r.GetField("xdpi")
    Dim xh As Float = GetDeviceLayoutValues.Height/r.GetField("ydpi")
    Log(xw & TAB & xh & TAB & Sqrt(xw * xw + xh * xh))  'Log: 5.787403583526611    7.716537952423096    9.645672680785086
Is there a cure for that?

I mean, is there a way to say to b4a to use different value for the dip so that dont need to change the entire app beacuse this wrong estimate ?
 
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
Well, I don't use custom designer scripts, but I do know that "autoscale" is not the solution, certainly not for code generated views.
This is "tongue-in-cheek" but you could replace "dip" with "*Xdip" (where Xdip is the exact value) in all relevant code.
If you try that, make sure you have a copy of your project.

There are likely better solutions, lets appeal to the rest of community.
 
Upvote 0

Marvel

Active Member
Licensed User
There is an accessibility settings called display size setting on some android phones that can be used to set everything to look bigger. That's probably the reason it's showing the device scale as 1.5. If that's case, you can divide your font/view size by the device scale to bring the scale back to 1.0

On Xiaomi phones, you can find it under text settings > display size

Considering people actually make their screens more accessible by making things bigger (maybe for older people) it's not exactly the best choice
 

Attachments

  • Screenshot_2021-10-02-21-01-01-176_com.android.settings.jpg
    Screenshot_2021-10-02-21-01-01-176_com.android.settings.jpg
    196.5 KB · Views: 50
Upvote 0

eelias

Active Member
Licensed User
Longtime User
There is an accessibility settings called display size setting on some android phones that can be used to set everything to look bigger. That's probably the reason it's showing the device scale as 1.5. If that's case, you can divide your font/view size by the device scale to bring the scale back to 1.0

On Xiaomi phones, you can find it under text settings > display size

Considering people actually make their screens more accessible by making things bigger (maybe for older people) it's not exactly the best choice
This was helpful, reducing 1 scale it got closer to what is needed. Still little strange but better... Surelly is a temporary remedy, but I need a way to calibrate the size of 1 dip otherwise it will be a mess in some of these equipments.
 
Upvote 0

eelias

Active Member
Licensed User
Longtime User
changing the screen size reduced the scale from 1.5 to 1.275 and the screen is now a little better.

Sad that it does not have a way to reach scale=1

1633224513290.png
 
Upvote 0

Marvel

Active Member
Licensed User
changing the screen size reduced the scale from 1.5 to 1.275 and the screen is now a little better.

Sad that it does not have a way to reach scale=1

View attachment 119815

Did you try dividing the height or width of the views by the scale? You will need to do it for all views, that's the only way I think you can solve this.

I use the code below in a class (mostly for text views so I'm not sure how well it will work for other views). This way, you don't need to change the screen size. Your app will stay the same on all display sizes.

Note that it might make your app slower when creating views


B4X:
Sub Class_Globals
    Private Accessibility As Accessibility
    Private FontScale As Float
End Sub

Public Sub Initialize
    FontScale = Accessibility.GetUserFontScale
End Sub

Sub SetFontSize(View As B4XView)
    If FontScale > 1 Then
        View.TextSize = View.TextSize/FontScale
    Else
        Return
    End If
End Sub

Sub ScaleAllTexts(Root As B4XView) 'Call this sub to scall all texts, you can modify it for views height and width too
    For Each v As View In Root.GetAllViewsRecursive
        If v Is Label Then
            SetFontSize(v)
        End If
    Next
End Sub
 
Last edited:
Upvote 0
Top