TextView极细字体

先看UC浏览器的温度
TextView极细字体
文章图片
uc_weather.png 要实现17°这样的极细的字体
自定义View
继承TextView,在onDraw方法中设置画笔粗细

TextPaint tp = new TextPaint(); tp.setAntiAlias(true); tp.setStyle(Paint.Style.FILL_AND_STROKE); tp.setStrokeWidth(0.1f);

setStrokeWidth方法默认参数是0,而且不接受负数参数,也就是说,只能加粗不能变细。
Spannable
再试试Spannable
Spannable s = new SpannableString("17°29"); s.setSpan(new AbsoluteSizeSpan(30, true), 0, 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); s.setSpan(new AbsoluteSizeSpan(30, false), 3, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); s.setSpan(new RelativeSizeSpan(2.0f), 0, 3, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(s);

效果也是一样,可以改变字体大小,但是只能加粗不能变细
Thin字体
从字体本身出发,尝试寻找细细的字体
http://stackoverflow.com/questions/19691530/valid-values-for-androidfontfamily-and-what-they-map-to?answertab=votes#tab-top
Added in Android Jelly Bean (4.1) - API 16 :
Regular (default):
sans-serif normal

Italic:
sans-serif italic

Bold:
sans-serif bold

Bold-italic:
sans-serif bold|italic

Light:
sans-serif-light normal

Light-italic:
sans-serif-light italic

Thin :
sans-serif-thin normal

Thin-italic :
sans-serif-thin italic

Condensed regular:
sans-serif-condensed normal

Condensed italic:
sans-serif-condensed italic

Condensed bold:
sans-serif-condensed bold

Condensed bold-italic:
sans-serif-condensed bold|italic

Added in Android Lollipop (v5.0) - API 21 :
Medium:
sans-serif-medium normal

Medium-italic:
sans-serif-medium italic

Black:
sans-serif-black italic

我自己的尝试

TextView极细字体
文章图片
me_weather.png 系统字体的位置
D:\Android\sdk\platforms\android-N\data\fonts
【TextView极细字体】fonts.xml里配置了字体的别名

    推荐阅读