安卓text view

    技术2024-08-13  61

    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" />

    第二种方法 例如是姓名 用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" />

    如我们写的账号、密码、性别等。

    Processed: 0.017, SQL: 9