Android控制文字水平間距android:letterSpacing
附錄文章1實(shí)現(xiàn)的是Android的文字在水平方向的縮放,然而不是水平方向的文字間距。如果要想實(shí)現(xiàn)Android TextView之類(lèi)的文字保持間距,那么需要設(shè)置android:letterSpacing,android:letterSpacing的值是一個(gè)浮點(diǎn)數(shù),為標(biāo)準(zhǔn)字體的倍數(shù)作為間距。寫(xiě)一個(gè)小demo示例。
Xml布局代碼:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Zhang Phil CSDN 默認(rèn)" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.1"
android:text="Zhang Phil CSDN 0.1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.2"
android:text="Zhang Phil CSDN 0.2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.3"
android:text="Zhang Phil CSDN 0.3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.4"
android:text="Zhang Phil CSDN 0.4" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:letterSpacing="0.5"
android:text="Zhang Phil CSDN 0.5" />
</LinearLayout>
