How do I convert pt to sp?

2019-01-17 03:02发布

I am a visual designer, working on an android design and I"m trying to spec my PSD file for our engineers. I cannot seem to find any documentation regarding the conversion of point size to SP for the type in any Android documentation. (Just that SP should be used for type).

6条回答
做自己的国王
2楼-- · 2019-01-17 03:21

The problem is that it depends on the density. Really, they're not good measurements to try to compare.

  • Points: There are 12 points in a pica, 6 picas per inch, so 72 (more accurately 72.27) points per inch.

  • Device-Independent Pixels (DP): These will be equal to the pixel size for MDPI displays, 1.5x the pixel size for HDPI displays, and 2x the pixel size for XHDPI displays. (e.g. 12dp = 12px MDPI, 18px HDPI, 24px XHDPI).

  • Scaled Pixels: These will be equivalent to the DP value, but scaled according to the user preference to be smaller or larger.

If you're designing at 72 dpi (Photoshop default DPI setting), an 8pt font would be equivalent to 8px, which would be 8px at MDPI, 12px at HDPI, and 16px at XHDPI, or more simply 8dp for all densities. I don't know how much scaling gets applied to different SP settings, so you'd have to hunt that out, but basically I would just give them the mockup and let them size it appropriately from there -- surely they can get it pretty close visually from that.

查看更多
\"骚年 ilove
3楼-- · 2019-01-17 03:26

There are 72 pts per inch, and 160 sp per inch (with standard font size in the device settings). this means there are 160sp per 72pts. 160sp/72pts simplifies to 20/9. So when converting pts to sp or dp use pts*20/9. As mentioned by others here already, sp does vary by the user's settings so if you don't want the text size to change with the device settings, then use dp.

查看更多
做个烂人
4楼-- · 2019-01-17 03:27

This is a great tool to help convert between the various measurements - put in what you know and it'll calculate the rest!

http://angrytools.com/android/pixelcalc/

查看更多
Summer. ? 凉城
5楼-- · 2019-01-17 03:28

In contrast to dp (and sp with minus the user text sizing factor), pt has pretty much the exact same physical measurement. Dp is more or less a rough approximation, since it uses the same factor for a wide dpi range.

You cannot convert pt to sp, like said by Flavio. You can, however convert pt to dp roughly (+/- 30% in extreme cases, but at least expect +/-10%).

Using the dpi buckets (ldp=120,mdpi=160,hdpi=240,xhdpi=320) the most generic conversion factor would be x0.45 (= 72/120*0.75 = 72/160*1 = 72/240*1,5 = 72/320*2) if using the exact dpi bucket values.

For more precise factors:

  • mdpi (scaling factor: 1.0) 10.1" WXGA Screen (149dpi) is 0.483076923 (= 72/149 * 1.0)
  • hdpi (scaling factor: 1.5) Nexus 7 (216dpi) is 0.5 (= 72/216 * 1.5)
  • xhdpi (scaling factor: 2.0) Nexus 10 (300dpi) is 0.48 (= 72/300 * 2)

So 12 pt would be on...

  • 10.1" WXGA: 24.84dp
  • Nexus 7: 24 dp
  • Nexus 10: 25dp
  • dpi bucket value: 26.666dp

You could use the same values for sp, but keep in mind, that these could be in/decreased by the users settings.

查看更多
▲ chillily
6楼-- · 2019-01-17 03:32

There's no direct mapping between pixels and sp, since sps are dynamically set as the users change the device font size in system settings. The user may want to see all the app fonts in smaller or larger sizes. It's an accessibility feature provided by the OS.

查看更多
Root(大扎)
7楼-- · 2019-01-17 03:35

^What Flavio said. but check out the display metrics class overview on the Android Developers site. You might find what you need here... http://developer.android.com/reference/android/util/DisplayMetrics.html#

查看更多
登录 后发表回答