问题
In design I have a text field with 16 as text size and 0.6 as character spacing
But, if I set this value for android:letterSpacing
attribute of TextView
spacing will be much more larger than in design.
So, what is the way to convert sketch value to android value?
回答1:
According to Romain Guy, Android uses the "1 em = font size" definition, so you'd just do
setLetterSpacing(characterSpacing / textSize)
...just make sure those values are in the same unit (dp vs px)
回答2:
If Sketch provides the letter spacing value in Points, then the following is the conversion:
float textSizePx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, textSizeInSp, displayMetrics);
float letterSpacingPx = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_PT, sketchLetterSpacing, displayMetrics);
float androidLetterSpacing = letterSpacingPx / textSizePx
return androidLetterSpacing;
回答3:
Check out android:textScaleX
Depending on how much spacing you need, this might help. That's the only thing remotely related to letter-spacing in the TextView.
来源:https://stackoverflow.com/questions/39100969/how-to-calculate-letterspacing-for-textview-from-sketch-values