## Figuring out display size in inches or mm

Problems with Canvas, OpenGL, etc...

### Figuring out display size in inches or mm

Hello,

I've been using the DisplayMetrics class to try and have my app figure out the physical size of the display it is running in. This way I can render images of specific sizes in physical dimensions. For example, I'd like to render a circle with diameter 10mm or let's say a diameter of 1inch regardless of the display the app is running in.

heightPixels and widthPixels seem to work in figuring out how many display pixels there are. However, the xdpi and ydpi fields make no sense.

For example, on the Motorola backflip, I see 480x320 for height and width, which matches the physical pixels of the display.

the xdpi field reports 159.3723, and the ydpi field reports 160.41878. Also just as an FYI, the scaled density and scaledDensity are reported as 1.0.

Anyway, if you do the math, it seems like xdpi and ydpi are wrong. For example, with a ruler I measure about 1 and 11/16 inches by 2 and 9/16 inches.

320*(1 and 11/16 inches) = 189 which is wrong. You can try all combinations to calculate this, and they are all wrong.

What on earth is xdpi and ydpi then?
CrazyJay09
Junior Developer

Posts: 16
Joined: Wed Aug 04, 2010 3:23 am

### Re: Figuring out display size in inches or mm

If you use the density field (160 on this phone) and calculate the size of the screen in inches knowing the height and width of your display. The size comes out to 3 inches by 2 inches, which is grossly wrong.

You can't seriously tell me google thinks that's good enough?
CrazyJay09
Junior Developer

Posts: 16
Joined: Wed Aug 04, 2010 3:23 am