Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 932
user1506104 Avatar asked Oct 22 '25 16:10

user1506104


2 Answers

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.

like image 85
Akash Gaonkar Avatar answered Oct 25 '25 05:10

Akash Gaonkar


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
like image 20
Frandall Avatar answered Oct 25 '25 04:10

Frandall