0

I wonder why Eclipse show: enter image description here

I thought that since "dp" is prone to be not accurate because of "density buckets" ~

http://developer.android.com/design/style/metrics-grids.html

and "mm" and "in" (with which the same warning is shown) in contrast the "dp" unit are the most accurate units (in the sense that 1 inch is really 1 inch on the screen).

What's interesting is the fact that "pt" don't make eclipse to show such a warning.

I thought that "mm" "in" and "pt" behave the same way (they are super accurate, because don't depend on density bucket).

Thank you very much for the answer.

Paweł Brewczynski
  • 2,665
  • 3
  • 30
  • 43
  • Notice that the message says that milimeters are not accurate **on all devices**. One milimeter is one milimeter anywhere in the universe that's not too close to a black hole, but cheap (expletive redacted) devices may not be able to accurately measure that. The problem is on the potential device your app will run in, not on your code. – Geeky Guy Sep 09 '13 at 19:08
  • 2
    Probably because millimeters don't correspond directly to a set number of pixels. The number of pixels to a millimeter are dependent on the screen density, and depending on the device you might end up with fractional pixels or some such nonsense. – thegrinner Sep 09 '13 at 19:10
  • @Renan But still it is misleading because it is the most accurate unit, it is higher probability that you get inaccuracy with "dp" (because of density buckets) than with "mm" because of problem with device software/hardware. – Paweł Brewczynski Sep 09 '13 at 19:12
  • @bluesm I don't think so, read thegrinner's comment. If you go too deep into this, you'll end up in a semanthycs labyrinth anyway. And in the end, the compiler is giving you a warning, not an error, so you can go with SI units if that's what beats your kink. – Geeky Guy Sep 09 '13 at 19:18
  • @thegrinner So it would round it up, and then it still be the most accurate. By the way. Why "pt" doesn't show warning ? – Paweł Brewczynski Sep 09 '13 at 19:22
  • That could be a reasonable behavior, but I doubt there's a guarantee. One manufacturer might round up, another down, and a third could invent their own form of rounding for tablet vs phone pixels. It's inaccurate in the sense that its mapping to actual pixels is undefined. – thegrinner Sep 09 '13 at 19:27

1 Answers1

0

You are correct in that dp is not completely accurate because of the density buckets. The size of one dp can be between 88% and 117% of the size of one dp on a device where where true dpi exactly matches the bucket dpi depending on how big the difference is between the true dpi and the bucket dpi. With a bigger ratio than that the device should be put into the next/previous bucket instead.

As you say mm, inch and pt is more exact since these are based on the true physical dpi and not the bucket dpi.

However, there are some devices available on the market that report incorrect physical dpi to Android (DisplayMetrics.xdpi and DisplayMetrics.ydpi) so because of this anything using mm, in or pt on these devices will get wrong sizes.

Examples of devices that report incorrect physical dpi include: Samsung Galaxy Mini, Samsung Galaxy S3 Mini, Lg Optimus 2X, Motorola Defy.

This is why Eclipse say that these units does not work accurately on all devices. The reason why there is no warning for pt is probably because the developers who added this warning just forgot about pt, or never tested this on a problematic device.

For further details on the same topic, please see my answer to the question Why Lint shows warning when using in (inch) or mm (millimeter) units as dimension?

Community
  • 1
  • 1
nibarius
  • 4,007
  • 2
  • 38
  • 56