当前位置: 移动技术网 > IT编程>移动开发>Android > Android TextView对齐的两种方法

Android TextView对齐的两种方法

2019年07月24日  | 移动技术网IT编程  | 我要评论

双色球2014081,喜讯网,新时代恋爱演员表

android textview对齐的两种方法

 在写android布局文件时, 经常碰到如下图的textview左右对齐的情况, 即姓名和手机号码纵向对齐。、 

 

第一种方法:  在姓和名之间加空格, 但是如果用键盘的空格会在一些机型上对齐、一些机型上不对齐。 

     \u3000是全角空格;  \u0020是半角空格,效果跟在英文输入法下直接敲键盘空格一样。 这里要用全角空格,  占位一个汉字。

<textview
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="姓\u3000\u3000名"
  android:textcolor="#6e6e6e"
  android:textsize="13dp" />

第二种方法: 比较low。    用3个textview, 第一个是“姓”、第二个是invisible(利用不显示但占位的特性)的2个汉字如“姓名”, 第三个是“名”。

<textview
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓"
            android:textcolor="#6e6e6e"
            android:textsize="13dp" />
          <textview
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="姓名"
            android:visibility="invisible"
            android:textcolor="#6e6e6e"
            android:textsize="13dp" />
          <textview
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="名"
            android:textcolor="#6e6e6e"
            android:textsize="13dp" />



以上就是关于android textview 文本对齐的方法详解,如有疑问还请大家留言,或者到本站社区交流,共同进步,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网