Pixels instead of dp in Designer

I tested that in Design panel the Height and Width "pixels" options are not in pixels (px) but in dp. I did not check every control but for layouts and buttons are in dp. I am writing a simple screen test program to check if it is true for every other control, in this case at least "pixels" should be changed in "dp" but I would prefer to add one more option so that we could choose between pixels, dp and percentage. Instead, for texts/fonts the size seems to be in sp. I checked with my smartphones and others and everything is right, to acquire the phones screen data I used the "my device" app and I checked its data with AI2 measurements. To convert dp to pixels: px = dp * density you can read density from "my device" or assume: density = dpi / 160 and read dpi from "my device" (the 1st dpi data).
My phone example:
Xiaomi POCO M2103K19PG:
screen res: 2167 x 1080 px
440 dpi
font scale=1.00

Data returned by AI2:
screen width = 392 -> 392*2.75 = 1078
screen height = 788 * 2.75 = 2167

This has been known for a long time and is an issue that may never be solved.

I think @Boban was able to retrieve device dpi information through Javascript in a WebViewer.
Unfortunately, I have lost the thread.

What I meant was AI2 itself is unlikely to be updated. We will always need some work around or another.

Why should not be updaed anymore?

We'd have to really think that through. I think it makes perfect sense to have font size be sp and other pixels sizes be dp. sp scales with user-controllable settings such as system-wide font size, so it makes little sense to have font be anything else (read more here). Regarding dp, recall that App Inventor is intended for educational use, and imagine how complicated a classroom experience might be if everyone tries to follow a tutorial and due to the mix of device screen densities in the room get wildly different UI layouts. By keeping the pixels relatively sized based on density it alleviates those headaches. Changing the semantics to be raw pixels likely would break most existing apps, so there would need to be some other mechanism to do measurements in terms of raw pixels.


Maybe just a checkbox that would be checked by default. Checkbox checked - DP, unchecked - PX. I don't think it would spoil the existing projects.

Yes and no. Any extensions that manipulate visible components would also need to be updated to reflect this change.


I created an extension for DisplayMetrics:

1 Like

Galaxy Note 8 ........................................ Pixel 2XL


1 Like

Very nice. Should be useful for resizing fonts.

Edit: Never mind, just realised it’s an apk and not an aix.

Could be useful if you publish the aix also, it looks good (apart the missing 'e' in Height but not so relevant).

Thanks for the hint. Spelling doesn't seem to be my forte - not even in my mother tongue (German). :upside_down_face:

I'll do it soon ...

It is a good news, well done Anke.

I increased the font size in the device settings:

1 Like

Hi Anke - could you add Height Millimeters and Width Millimeters to your extension please? A lot of us, especially young Europeans, think in metric.

Ok, done:


I released the extension.

1 Like

Nice one Anke :sunglasses:

1 Like