为什么要用sp来表示Android中的字体大小呢?(复制)

时间:2022-09-11 10:35:42

Possible Duplicate:
Difference of px, dp, dip and sp in android

可能重复:px, dp, dip, sp在android中的差异

I am new to Android and I was trying out this tutorial

我是Android新手,我正在尝试本教程

In that tutorial, they used the unit "sp" for textSize attribute and "dp" for other attributes.

在本教程中,他们使用单元“sp”表示textSize属性,“dp”表示其他属性。

Please tell me how sp differs from dp?

请告诉我sp和dp有什么不同?

2 个解决方案

#1


223  

The dp has constant ratio transition to px: dp = px * ratio. Where ratio will never change on any particular device.

dp与px的比值为常数:dp = px *。在任何特定的设备上,比例永远不会改变。

While sp (s for scaled) has scalable ratio: sp = px * ratio * scale. Where 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.

而sp (s)具有可伸缩比例:sp = px *比值*比例。比例永远不会改变,但比例是用户可配置的。这个比例可以用于需要更大字体的人,例如,使用设备更舒适。

#2


6  

Sp is scaled independently with respect to the normal font size of the device. http://developer.android.com/guide/practices/screens_support.html

Sp是根据设备的正常字体大小独立伸缩的。http://developer.android.com/guide/practices/screens_support.html

Similarly, you should prefer the sp (scale-independent pixel) to define text sizes. The sp scale factor depends on a user setting and the system scales the size the same as it does for dp.

类似地,您应该更喜欢sp(与比例无关的像素)来定义文本大小。sp比例因子取决于用户设置,系统的比例大小与dp相同。

#1


223  

The dp has constant ratio transition to px: dp = px * ratio. Where ratio will never change on any particular device.

dp与px的比值为常数:dp = px *。在任何特定的设备上,比例永远不会改变。

While sp (s for scaled) has scalable ratio: sp = px * ratio * scale. Where 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.

而sp (s)具有可伸缩比例:sp = px *比值*比例。比例永远不会改变,但比例是用户可配置的。这个比例可以用于需要更大字体的人,例如,使用设备更舒适。

#2


6  

Sp is scaled independently with respect to the normal font size of the device. http://developer.android.com/guide/practices/screens_support.html

Sp是根据设备的正常字体大小独立伸缩的。http://developer.android.com/guide/practices/screens_support.html

Similarly, you should prefer the sp (scale-independent pixel) to define text sizes. The sp scale factor depends on a user setting and the system scales the size the same as it does for dp.

类似地,您应该更喜欢sp(与比例无关的像素)来定义文本大小。sp比例因子取决于用户设置,系统的比例大小与dp相同。