Android控制文字水平间距android:letterSpacing

来源:互联网 发布:奥比岛刷奥币软件 编辑:程序博客网 时间:2024/05/16 14:58

Android控制文字水平间距android:letterSpacing

附录文章1实现的是Android的文字在水平方向的缩放,然而不是水平方向的文字间距。如果要想实现Android TextView之类的文字保持间距,那么需要设置android:letterSpacing,android:letterSpacing的值是一个浮点数,为标准字体的倍数作为间距。写一个小demo示例。
Xml布局代码:

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"  
  5.     android:orientation="vertical">  
  6.   
  7.     <TextView  
  8.         android:layout_width="wrap_content"  
  9.         android:layout_height="wrap_content"  
  10.         android:text="Zhang Phil CSDN 默认" />  
  11.   
  12.     <TextView  
  13.         android:layout_width="wrap_content"  
  14.         android:layout_height="wrap_content"  
  15.         android:letterSpacing="0.1"  
  16.         android:text="Zhang Phil CSDN 0.1" />  
  17.   
  18.     <TextView  
  19.         android:layout_width="wrap_content"  
  20.         android:layout_height="wrap_content"  
  21.         android:letterSpacing="0.2"  
  22.         android:text="Zhang Phil CSDN 0.2" />  
  23.   
  24.     <TextView  
  25.         android:layout_width="wrap_content"  
  26.         android:layout_height="wrap_content"  
  27.         android:letterSpacing="0.3"  
  28.         android:text="Zhang Phil CSDN 0.3" />  
  29.   
  30.     <TextView  
  31.         android:layout_width="wrap_content"  
  32.         android:layout_height="wrap_content"  
  33.         android:letterSpacing="0.4"  
  34.         android:text="Zhang Phil CSDN 0.4" />  
  35.   
  36.     <TextView  
  37.         android:layout_width="wrap_content"  
  38.         android:layout_height="wrap_content"  
  39.         android:letterSpacing="0.5"  
  40.         android:text="Zhang Phil CSDN 0.5" />  
  41.   
  42. </LinearLayout>  


代码运行结果:


附录文章:
1,《Android控制水平方向字体缩放android:textScaleX》链接地址:http://blog.csdn.net/zhangphil/article/details/51306064 

原创粉丝点击