Wednesday, August 4, 2010

[android-developers] how to get the screen size in inches...

I am trying to determine the physical size of a screen in inches.

Normally, I could do something like this:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics( metrics );

Then use metrics.widthPixels and metrics.heightPixels. Now that I
know the width and height in pixels, I should be able to calculate
size in inches if I know the density. Easy enough, metrics.xdpi and
metrics.ydpi.

Then screen dimension in inches should be:

widthInInches = metrics.widthPixels / metrics.xdpi;
heightInInches = metrics.heightPixels / metrics.ydpi;

Seems simple enough except that it doesn't work.

On a Motorola Droid, the system reports back: xdpi and ydpi as 96
(which cannot be true).

And the screen resolution as: 480 x 854. Which results in a width of
5" x 8.9" -- which as I'm holding this in my hand right now, I must
say - cannot be correct.

Any ideas on how to accurately calculate this?

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment