25 Aug 2015

How do convert pt to sp in Android?

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.

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 converstion 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.