How do dp, dip, dpi, ppi, pixels and inches relate?

前端 未结 5 1144
别那么骄傲
别那么骄傲 2020-12-24 02:33

I was reading dp, dip, px, sp measurements, but I still have some questions about dp/dpi vs ppi vs px vs inch. I am not able to compare them... is an inch the largest?

5条回答
  •  孤城傲影
    2020-12-24 02:39

    You should (almost) always use flexible sizing units, like dp, which is Density-Independent Pixels, because 300px on one device is not necessarily the same amount of screen real estate as 300px on another. The biggest practical implication is that your layout would look significantly different on devices with a different density than the one your design targeted.

    • dp or dip means Density-independent Pixels
    • dpi or ppi means Dots (or Pixels) Per Inch
    • inch is a physical measurement connected to actual screen size
    • px means Pixels — a pixel fills an arbitrary amount of screen area depending on density.

    For example, on a 160dpi screen, 1dp == 1px == 1/160in, but on a 240dpi screen, 1dp == 1.5px. So no, 1dp != 1px. There is exactly one case when 1dp == 1px, and that's on a 160dpi screen. Physical measurement units like inches should never be part of your design—that is, unless you're making a ruler.

    A simple formula for determining how many pixels 1dp works out to is px = dp * (dpi / 160).

提交回复
热议问题