androidtextview

How to convert SP to EM?


In API 21, setLetterSpacing(float) was introduced. The problem is, the parameter is in em units. Many of app graphic designers I've worked with use sp to measure their letter spacing. So if I was given

Letter Spacing: 1.6sp

I usually end up trying out several floating point numbers that will result to something that closely resembles that of the designer's. In short, it's not pixel-perfect.

Do you know of any better way to convert from SP to EM? Thanks!


Solution

  • Based on android documentation about dimension SP behaved like DP but for font size. Converting may result in inconsistency based on the screen size and resolution, but here the formula I found:

    sp * 0.0624 = em