先看UC浏览器的温度
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字体
从字体本身出发,尝试寻找细细的字体
Added in Android Jelly Bean (4.1) - API 16 :
Regular (default):
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">normal</item>
Italic:
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">italic</item>
Bold:
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold</item>
Bold-italic:
<item name="android:fontFamily">sans-serif</item>
<item name="android:textStyle">bold|italic</item>
Light:
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">normal</item>
Light-italic:
<item name="android:fontFamily">sans-serif-light</item>
<item name="android:textStyle">italic</item>
Thin :
<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textStyle">normal</item>
Thin-italic :
<item name="android:fontFamily">sans-serif-thin</item>
<item name="android:textStyle">italic</item>
Condensed regular:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">normal</item>
Condensed italic:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">italic</item>
Condensed bold:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">bold</item>
Condensed bold-italic:
<item name="android:fontFamily">sans-serif-condensed</item>
<item name="android:textStyle">bold|italic</item>
Added in Android Lollipop (v5.0) - API 21 :
Medium:
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">normal</item>
Medium-italic:
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:textStyle">italic</item>
Black:
<item name="android:fontFamily">sans-serif-black</item>
<item name="android:textStyle">italic</item>
我自己的尝试
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="60sp"
android:layout_gravity="center_horizontal|bottom"
android:textColor="@color/colorAccent"
android:gravity="center"
android:textStyle="normal"
android:fontFamily="sans-serif-thin"
android:text="17°"/>
me_weather.png
系统字体的位置
D:\Android\sdk\platforms\android-N\data\fonts
fonts.xml
里配置了字体的别名
网友评论