我想知道为什么我的 TextView 大小对于不同的设备是不同的,即使我将文本大小设置为 sp 或 dp。
最佳答案
This post解释区别:
dip/dp(密度独立像素):
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. The ratio of dp-to-pixel will change with the screen density, but not necessarily in direct proportion. Note: The compiler accepts both "dip" and "dp", though "dp" is more consistent with "sp".
sp(缩放独立像素):
like the dp unit, but it is also scaled by the user's font size preference. It is recommend you use this unit when specifying font sizes, so they will be adjusted for both the screen density and user's preference.
和this post解释为什么 dp
和 sp
值可能不同:
The dp has constant ratio transition to pixels:
dp = px * ratio
. Ratio will never change on any particular device.The sp has scalable ratio:
sp = px * ratio * scale
. Ratio never changes, but scale is user configurable. This scale can be used by people who need larger font sizes, for example, to use device more comfortably.
关于Android 为什么即使在 sp 中指定了一种文本大小,所有设备的文本大小也不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26122342/