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!
I believe sp and em have different purposes -- sp is used to absolutely size text, while em is for relative sizing. My guess would be that the em letter spacing is some multiple of the size of the text, so if you know the text size, and the desired spacing, the equation would be spacing_em = spacing_sp / text_size_sp.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With