android dp 与 px 的换算

来源:互联网 发布:热血江湖网络不稳定 编辑:程序博客网 时间:2024/04/27 21:34


Density-independent pixel (dp)

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


0 0
原创粉丝点击