Odd problem matching sprite height to canvas

It depends on device.
There is no any relationship between XDpi & YDpi

Ok, so they are always equal (on a specific device)?

Pixels are square, so the number of pixels per inch will be equal vertically and horizontally.

Maybe some devices have rectangular pixels, which I doubt. Then they may differ.

No in your case they are the same but maybe in my device may not.

@Anke

In this case they are not same.

1 Like

So pixels are rectangular after all: D

Ah, thanks. I missed this post.

1 Like

a pixel is not always square . It depends on the screen, and how many dots per inch (DPI) it has in each direction.

Thank you for the explanation.

DisplayMetrics is really a rather opaque topic in Android.

1 Like

I'm guessing this issue would show up in most sprite properties, like height, width, x, y etc.

:grinning: :grinning: whenever the device density came into the picture problem will occur.

1 Like

That would be the way to go.

https://developer.android.com/training/multiscreen/screendensities

2 Likes

Originally App Inventor was designed to work with what are now called medium DPI screens (where density = 1.0)--mainly because at that time in the Android system it was the only density. Of course, the fragmentation of the Android hardware ecosystem has resulted in many different density displays both in terms of the DPI, aspect ratios, and even pixel sizes. The ideal solution would be to simply change the return types of positioning variables like X, Y, Width, and Height to be float instead of int. Practically though, we try not to change any publicly facing APIs since they may be relied on by extensions and would break any existing projects. However, only 2% of projects use extensions and fewer than those might be using extensions that manipulate views, so it's probably fine. Realistically, this changeover should have been done 10 years ago when Google started allowing for different DPI devices.

4 Likes

That makes sense. I'm really appreciative of how actively ai2 is maintained and users like me are supported.

2 Likes