Did you try fetching the scale that will allow you to convert from DPI
to actual screen pixels?  I found this very reliable:

     final scale =
getContext().getResources().getDisplayMetrics().density;

Then multiply scale by one inch of pixels in DPI resolution (depending
on the screen you're on) - 120, 160, 240, 320.

This API call ...

     int densityDpi =
getContext().getResources().getDisplayMetrics().densityDpi;

will tell you the density of the screen you're on.  See
http://developer.android.com/reference/android/util/DisplayMetrics.html#densityDpi
for more information.

So, this will tell you how many screen pixels equate to an inch.  Then
you can use that to lay out your ruler markings:
     int pxPerInch = 340; // default value - note it's a new density
in API version 9.

     switch(densityDpi){
          case DisplayMetrics.DENSITY_LOW:
                      pxPerInch = 120 * scale;
                      break;
          case DisplayMetrics.DENSITY_MEDIUM:
                      pxPerInch = 160 * scale;
                      break;
          case DisplayMetrics.DENSITY_HIGH:
                      pxPerInch = 240 * scale;
                      break;
     }

I haven't tested that but it, or some derivation of this should tell
you how many screen pixels comprise one inch on the screen.



Reference: http://developer.android.com/guide/practices/screens_support.html

Richard


On Jan 12, 10:38 am, Phil Endecott <spam_from_goo...@chezphil.org>
wrote:
> > > Note that some devices don't correctly report actual resolution (xdpi /
> > > ydpi).
>
> > Does "some devices" include anything that I care about?  How wrong is
> > the value?
>
> Answering my own question: yes, it is wrong on my Motorola Defy, which
> returns 96.  Googling tells me it is wrong on quite a lot of devices
> from Motorola.  Aaarrgghhhh.
>
> So: is the value 96 that I see a sentinel that I can use to detect
> this bug?  I.e. do all/most devices with this bug return 96?  If so,
> I'll trap 96 and substitute something else, e.g.
> DisplayMetrics.displayDpi(), which I trust is more reliable.  If 96 is
> not the only wrong answer, can anyone suggest some other way to detect
> a bogus value here?
>
> Thanks,  Phil.

-- 
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+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to