The density-independent pixel is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by the system for a "medium" density screen. At runtime, the system transparently handles any scaling of the dp units, as necessary, based on the actual density of the screen in use. The conversion of dp units to screen pixels is simple:
px = dp * (dpi / 160)
. For example, on a 240 dpi screen, 1 dp equals 1.5 physical pixels.
1 dp 相当于 在 160 dpi 的屏幕上的 1 个像素 px。单位 dp 到 px 的转化很简单: px = dp * (dpi / 160) 。例如在 240 dpi 的屏幕上,1 dp = 1.5 px