Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is dp based on the physical size of the screen? (dp =1/160 of an inch)

Tags:

android

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?

like image 323
Jesús Tomás Avatar asked Dec 21 '13 10:12

Jesús Tomás


2 Answers

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.

like image 51
zapl Avatar answered Oct 04 '22 19:10

zapl


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.

like image 29
Piyush Agarwal Avatar answered Oct 04 '22 21:10

Piyush Agarwal