DPI's on Android

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
Can someone please explain how CX handles different resolutions and DPI's on Android devices?

As I understand, when you start a CX application on Android, CX will present you with a fullscreen to work with.
You are then supposed to read the true pixel native width and height (without having DPI modes come in-between, that could in theory give you some lower number, right?) After this is done, you have to decide what to do with these numbers and how you want to scale things appropriately.

I think I understood that part correctly but how do you get the DPI-level that is used on a particular Android device?
Are you meant to calculate the DPI for yourself depending on the native true pixel resolution that is given you using the height and width commands?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
737
What do you need the DPI for? How would you approach scaling your content with it?
I am pretty happy with just scaling the same content to fill the screen. The only thing that took me some time was to get the best compromise regarding the x-y ratio.
If I could choose a metric for different screen resolutions I would like something like an average view angle or a screen diameter to average distance ratio.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
I am basically just afraid that Retina or something similar on Android will get me in trouble later on.
Are you saying that as long as you do not use native UI one will never get into trouble in screen area?

Will you always get the correct width & height in pixels back? Or are there special cases that you need to know about?
 

Phil7

Administrator
CX Code Contributor
3rd Party Tool Dev
Joined
Jun 26, 2017
Messages
737
Are you saying that as long as you do not use native UI one will never get into trouble in screen area?
As I see it this was the goal. But you know, targets are changing and there were allways some issues that needed to be fixed.

Will you always get the correct width & height in pixels back? Or are there special cases that you need to know about?
There was something about Android on some devices if I remember correctly were the screen resolution was scaled down for performance/energy reasons I guess.
But the content was still scaled to the whole screen area resulting in a smaller DPI value.
 

Wingnut

Well-known member
3rd Party Module Dev
Tutorial Author
Joined
Jan 2, 2020
Messages
1,284
I remember a lot of people had problems with the resolution on some Android devices, and I wonder if it was related to DPI, I would think so.

If so I might (not sure though) have found a solution. You simply add this line to the MANIFEST to disable pre-scaling.
This stops you from getting the wrong screen-size If the density is more than 1 I think.

<supports-screens android:anyDensity="true" />

like so :

XML:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="...."
android:versionCode="1"
android:versionName="1.0">
<supports-screens android:anyDensity="true" />  
<application android:label="@string/app_name" >
 
Top Bottom