Is this definition correct?
dp Density-independent Pixels - 1/160 of an inch based on the physical size of the screen.
I have found conflicting information:
The official documentation assumes scaled proportionally in equation “px = dp * (dpi / 160)”. Also here (3:02) Roman Nurik says “scaled proportionally”
But in official documentation:
px Pixels - corresponds to actual pixels on the screen. in Inches - based on the physical size of the screen. mm Millimeters - based on the physical size of the screen. pt Points - 1/72 of an inch based on the physical size of the screen. dp Density-independent Pixels - An abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi (dots per inch) screen, on which 1dp is roughly equal to 1px. When running on a higher density screen, the number of pixels used to draw 1dp is scaled up by a factor appropriate for the screen's dpi. Likewise, when on a lower density screen, the number of pixels used for 1dp is scaled down. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion.
If my definition is correct, Why introduce a new physical size measure if we already have the well-known mm, in and pt?
A measurement unit like mm
or in
would be way less confusing since dp
measures the same real world observed length. It would be misleading on the other hand since dp
is not an absolutely defined unit.
The use of screen density buckets means that dp
is a bit fuzzy - but it will stay within reasonable (+/-20% ?) accuracy. Real world displays are usually not exactly e.g. 160dpi they can be 173.4 dpi and still be classified as 160dpi. The math carried out to convert from dp
to pixels on the screen is done based on these buckets and that means that the accuracy of dp
depends on how accurately your device screen meets it's classification.
But to clear your doubt: 160dp is always 1 (fuzzy) inch regardless of what device you hold in your hand. Easier to think of: 50dp = 1 (small) finger wide.
px Pixels
on the other hand are actual pixels. A full HD display has 1920x1080 of them but that unit says nothing about the screen size or how big such a pixel will appear to the user. dp
or dip
is a different unit and should have never been called "pixel" in my opinion.
Check out this out after 20:00
http://www.youtube.com/watch?v=pBKGbCu0pJg&list=PLWz5rJ2EKKc8j2B95zGMb8muZvrIy-wcF
Join Nick Butcher, Adam Koch and Roman Nurik discussing all about Android Units of measure.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With