Android 屏幕密度 dpi 与 ppi

Android screen density dpi vs ppi

根据 android 文档,密度应为 dpi(每英寸点数),所有布局尺寸应为 dp.

并使用一个简单的公式 android 可以将 dp 映射到实际像素。

px = dp * (dpi / 160), 
160dpi ~ medium density screen which is the baseline

那么为什么不直接使用 ppi(每英寸像素数)来描述屏幕密度呢?

关于这个问题有很多文档,但我认为这部分与您的问题相关:

Supporting Multiple Screens

Density independence

Your application achieves "density independence" when it preserves the physical size (from the user's point of view) of user interface elements when displayed on screens with different densities.

Maintaining density independence is important because, without it, a UI element (such as a button) appears physically larger on a low-density screen and smaller on a high-density screen. Such density-related size changes can cause problems in your application layout and usability. Figures 2 and 3 show the difference between an application when it does not provide density independence and when it does, respectively.

据我所知,这是一个基于设计的区别;开发人员 不应该担心 他们要部署到的各个屏幕,并且应该在应用程序中使用 dp 以使其在不同的 android 设备上尽可能可移植。

对于资产的设计者来说,图像的显示尺寸和清晰度更重要,dpi 的区别对他们来说很重要。

有关详细信息,请查看 article/e-book 由 google 工程师撰写的文章:

http://sebastien-gabriel.com/designers-guide-to-dpi/

请特别查看 "The PPI Configuration" 部分。引用文章:

Anything non-print uses pixel sizes regardless of the initial PPI configuration... PPI configuration in software is a printing legacy. If you design only for the web, PPI won't have any influence on the size of your bitmap.