PC SOFT

FOROS PROFESIONALES
WINDEVWEBDEV y WINDEV Mobile

Inicio → WINDEV 2024 → Android DPI fun
Android DPI fun
Iniciado por guest, 31,jul. 2018 18:40 - 4 respuestas
Publicado el 31,julio 2018 - 18:40
Hi all

Been beating my head against a wall all day today but finally worked out how to handle getting the DPI of any android device.... To help anyone else who may suffer in the same way, here's how..

Identify a static control on your window (IMG_Menu in my case)

Since in the WM editor everything is always based on 160DPI you can use the CoordinateScreenToEditor command to work out what the DPI is.

all variables have 2 decimal places..
nX = CoordinateScreenToEditor(IMG_Menu..X)
gnDPIRatio = Round(IMG_Menu..X / nX,2)

MyDPI = 160 * gnDPIRatio

Boom!
Publicado el 31,julio 2018 - 19:50
Hi

it's certainly interesting, but it begs the question: why?

Best regards
Publicado el 31,julio 2018 - 20:42
Bosher,

I once found this piece of code. I use it to display the "density" of the screen in some kind of system-info screen in my apps.
I think this is your gnDPIratio .

Just create a global procedure as follows
import android.app.Activity; import android.content.Context; import android.view.View; import android.view.Window; import android.view.WindowManager; import android.util.DisplayMetrics; public static double getDisplayDensity() { // https://developer.android.com/reference/android/util/DisplayMetrics.html DisplayMetrics metrics = new DisplayMetrics(); getActiviteEnCours().getWindowManager().getDefaultDisplay().getMetrics(metrics); return metrics.density; }
Publicado el 31,julio 2018 - 22:02
Fabrice,

It's because I needed to change the fontsize in a listbox according to device resolution. Anchoring resizes the control fine, However, I compute the optimal fontsize using the textwidth trick just fine. The issue is that with a listbox you need to also change the lineheight property to get it to display correctly.

I've built an algorithm that does this quite well now.

The reason i'm using a listbox is because I need to alternate the colours of each line based on content.

It's a long story I know... :0

Cheers

Bob
Publicado el 31,julio 2018 - 22:03
Thanks Arie.

That looks useful!

Cheers

Bob