发布于 2017-10-02 21:06:56 | 181 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的精品教程,程序狗速度看过来!

Android移动端操作系统

Android是一种基于Linux的自由及开放源代码的操作系统,主要使用于移动设备,如智能手机和平板电脑,由Google公司和开放手机联盟领导及开发。尚未有统一中文名称,中国大陆地区较多人使用“安卓”或“安致”。


这篇文章主要介绍了Android TextView对齐的两种方法的相关资料,在开发Android APP 的时候经常会用到TextView 输入用户信息或者其他信息,总是不能对齐,这里提供两种方法,需要的朋友可以参考下

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 文本对齐的方法详解,如有疑问还请大家留言,或者到本站社区交流,共同进步,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务