dip :Density-independent pixel (dp)
android api 解释如下:
A virtual pixel unit that you should use when defining UI layout, to express layout dimensions or position in a density-independent way.
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. You should always use dp units when defining your application's UI, to ensure proper display of your UI on screens with different densities.
解释中给出了一个公式: px = dp * (dpi / 160)
dpi是什么:dots per inch(每英寸的像素点数) 用公式表达是 dpi = px / inch;
将两个公式合并有如下结果:
dp = px / dpi * 160;
dp = inch * 160;
由此可见,dp和inch是成正比的。
dp的本质,表示的是固定的长度。