根据dp的定义:
Density-independent Pixels - an abstract unit that is based on the physical density of the screen. These units are relative to a 160 dpi screen, so one dp is one pixel on a 160 dpi screen
我们可以计算出1dp = 1/160
英寸,这是一个物理尺寸。
然而 dp
似乎不像下表那样被视为物理尺寸,
此表来自What is the difference between “px”, “dip”, “dp” and “sp”?的回答
| Unit | Description | Units Per | Density | Same Physical Size |
| | | Physical Inch | Independent | On Every Screen |
+---------+-------------+---------------+-------------+--------------------+
| px | Pixels | Varies | No | No |
+---------+-------------+---------------+-------------+--------------------+
| in | Inches | 1 | Yes | Yes |
+---------+-------------+---------------+-------------+--------------------+
| mm | Millimeters | 25.4 | Yes | Yes |
+---------+-------------+---------------+-------------+--------------------+
| pt | Points | 72 | Yes | Yes |
+---------+-------------+---------------+-------------+--------------------+
| dp | Density | ~160 | Yes | No |
| | Independent | | | |
| | Pixels | | | |
+---------+-------------+---------------+-------------+--------------------+
| sp | Scale | ~160 | Yes | No |
| | Independent | | | |
| | Pixels | | | |
+---------+-------------+---------------+-------------+--------------------+
所以,是或否。
如果不是,为什么?谢谢!
最佳答案
好问题!
当他们说物理尺寸时,他们指的是物理像素数。
因为高分辨率屏幕每英寸的像素比低分辨率屏幕多。在较低分辨率的屏幕上,每 dp 的物理像素数会更少。
话虽这么说,但大多数手机屏幕并不完全适合任何水桶。然后发生的事情是 android 将它们放入最近的桶中,这可能导致每 dp 的像素数偏离桶数量。
关于android - dp(密度无关像素)是物理尺寸吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55719004/