开发者

Calculating physical screen size on Sony Ericsson X10? (it's coming out 1.5x too big)

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 Eri开发者_开发问答csson 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.


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.


I know this is an old question but the bug is still there. When using Display Metrics on (some) Sony devices you need to do the following :

metrics.setToDefaults();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜