The quantized density value (160/240 etc) is used by resource loading code,
and so can be expected to be there. Some devices deliberately use a value
that is not the closest match to the actual physical density, but it's the
same for all applications on the device.

The xdpi and ydpi can sometimes be completely nonsensical.

If you need exact actual physical screen density (e.g. for a ruler type
application), consider providing a calibration mode in your application.

--
Kostya Vasilyev
07.10.2011 16:50 пользователь "niels" <nioer...@googlemail.com> написал:

> Thanks for the info. As result of another discussion I already had a
> look at the DisplayMetrics class. They clearly state there, that I
> can't rely on dip because it's just based on the default density
> (160dpi, 240dpi, 320dpi, etc.) which is nearest to the device's real
> density. So this (official) docu is simply wrong:
> http://developer.android.com/guide/practices/screens_support.html
>
> So at least theory allows correct scaling, if I don't use XML (which
> from my point of view is a design error). But in practice HTC
> Sensation unluckily returns crap when trying to read ot X and Y DPI.
> Both values are around 160 whereas they should be something around
> 256.
>
> Regards,
> Niels
>
> On Oct 6, 4:54 pm, Studio LFP <studio....@gmail.com> wrote:
> > I don't think you will be able to do this with a XML layout. You probably
> > want to take a look at this
> >
> > http://developer.android.com/reference/android/util/DisplayMetrics.ht...
> >
> > There is both xdpi and ydpi. That should be checked to get the actual dpi
> in
> > both directions and then a view created with those calculations should
> get
> > you where you want to go.
> >
> > Here is what I get on a few of my devices in portrait mode:
> >
> > // --- Sample Code Start ---
> > DisplayMetrics metrics = new DisplayMetrics();
> > Display display = getWindowManager().getDefaultDisplay();
> > display.getMetrics( metrics );
> >
> > Log.i( "TestProject", "X DPI: " + metrics.xdpi );
> > Log.i( "TestProject", "Y DPI: " + metrics.ydpi );
> > // --- Sample Code End ---
> >
> > *Samsung Galaxy Tab (7 inch):*
> > X DPI: 168.89351
> > Y DPI: 169.33333
> >
> > *Motorola Droid Bionic:*
> > X DPI: 258.79245
> > Y DPI: 256.67368
> >
> > *Sony Xperia Play:*
> > X DPI: 239.05882
> > Y DPI: 243.72585
> >
> > Steven
> > Studio LFPhttp://www.studio-lfp.com
>
> --
> 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

-- 
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