Android Question GetDevicePhysicalSize detects wrong inches!

vfafou

Well-Known Member
Licensed User
Longtime User
Hello!

I have a 7" PX5 Android 10 car multimedia system with a resolution 1024 X 600 (fixed landscape orientation).
According to:
B4X:
Sub GetDevicePhysicalSize As Float
   Dim lv As LayoutValues
   lv = GetDeviceLayoutValues
   Return Sqrt(Power(lv.Height / lv.Scale / 160, 2) + Power(lv.Width / lv.Scale / 160, 2))
End Sub
the screen size is 4.945" and it causes problems to my app because I need to detect the right diagonal.
Is it something wrong or I'm missing something?
Is there any other way to detect the right screen size?

Thank you in advance!
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
You can get the same value with GetDeviceLayoutValues.ApproximateScreenSize.
The size is approximate because the scale value is an approximation. You can find the exact scale. Search for xdpi / ydpi.

Unless you are building a "ruler" type app, the exact size shouldn't matter and trying to match an exact size is a bad practice. Use anchors and designer script to build a flexible layout that will work with all screen sizes.
 
Upvote 0

vfafou

Well-Known Member
Licensed User
Longtime User
Hello Erel!
Thank you for your response!
My problem is not to fit the layout to all screens. I have already done it, but for portrait orientation. My case here is that the app is made with B4XPages and I have to decide the orientation programmatically when main activity is created. The app wasn't actually designed for landscape but my customer tried to install it to his car's multimedia system with the screen specs I refer to my first post and the app reasonably fitted the portrait layout variant because the screen recognised as 4.945 inches and not as a tablet one. The result was very bad!
Is it correct to check if layout values width > height to decide that orientation is landscape?
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…