Take the 2-minute tour ×

I am working on supporting multiple screen sizes in my Android app and I need to know the physical screen size of the device.

On a Sony Ericsson X10, I'm querying the physical screen resolution and density and trying to calculate the screen size (resolution/density = size) but the result is about 1.5 times the actual size!

Here's the code:

    DisplayMetrics metrics = c.getResources().getDisplayMetrics();
    mPhysicalScreenWidth  = metrics.widthPixels  / metrics.xdpi;
    mPhysicalScreenHeight = metrics.heightPixels / metrics.ydpi;
    Log.d(TAG, "DisplayMetrics: widthPixels=" + metrics.widthPixels + " xdpi=" + metrics.xdpi +
            " heightPixels=" + metrics.heightPixels + " ydpi=" + metrics.ydpi);
    Log.d(TAG, "Physical screen width=" + mPhysicalScreenWidth + "\", height=" + mPhysicalScreenHeight + "\"");

The output in the log:

DisplayMetrics: widthPixels=480 xdpi=160.41878 heightPixels=854 ydpi=159.49677
Physical screen width=2.9921684", height=5.3543406"

This actual size is only 2" (wide) x 3.5" (high)!?

Am I doing something wrong?

I am using the Android 1.6 SDK and I've set all the <supports-screens> attributes in the manifest to true.

share|improve this question
The actual dpi for the screen on this phone is 240. No idea why its being returned as 160 though. –  dave.c Jan 31 '11 at 20:38
Does it have something to do with "scaledDensity" parameter? It is exactly 1.5, as you report the difference. I have also found "densityDpi" parameter, that reports 240. –  Mike Bevz Jan 11 '12 at 10:32
add comment

1 Answer

up vote 1 down vote accepted

The only explanation I can think of is that the dpi values for the device are incorrect (sounds like false advertising to me Edit: false advertising to make them look worse?). The screen is rated at 4.0 inches in size, with 160 dpi resolution. The pixel values you have are correct, which means the inch sizes you have are correctly calculated. All the values I've found online (wikipedia, gsmarena) say the same thing.

But the screen size is actually 4.0 inches across...

sqrt ( 5.35^2 + 3.0^2) = 6.14 inches across, way larger than the actual.

This sounds like the dpi values must be incorrect. They must actually be a little larger. After plugging in a couple of values, the actual dpi must be around 240. I'm not sure as to why the values would be listed incorrectly everywhere...

Edit: After researching this a bit more, the xperia x10 is reported to have a dpi of 245 for both x and y.

share|improve this answer
add comment

Your Answer


