Android 为什么即使在 sp 中指定了一种文本大小,所有设备的文本大小也不同?

标签 android text-size

我想知道为什么我的 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解释为什么 dpsp 值可能不同:

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/

相关文章:

android View 旋转动画不会旋转焦点区域吗?

java - 结果rawResult.getContents android更改url

java - 没有 Wifi 无法定位

java - Firebase onDisconnect() 不工作

Android Text Size 支持多屏幕

android - 如何将以像素为单位的文本宽度转换为屏幕宽度/高度的百分比?

text-size - 使用 asciidoc 时,有什么方法可以更改特定 block 的文本大小(字体大小)?

android - 为什么我的回调在后台一段时间后为空(包括示例应用程序)

android - 修复了 WebView Android 中的文本大小(Lollipop)

Android:如何让Borderless button的文字大小和TextView一样