我是Activity上的textView,根据它从JSON响应接收到的参数显示,我需要将其限制为仅12个字符:
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/includeheadersetting"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Name"
android:textColor="#000000"
android:textStyle="bold" />
使用android:maxLength="12"
限制文本长度:
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/includeheadersetting"
android:layout_marginLeft="20dp"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Name"
android:maxLength="12"
android:textColor="#000000"
android:textStyle="bold" />
你也可以使用其他属性,如下所示:
android:ellipsize="end"
android:maxLines="1"
使用maxLength属性,然后使用android:ellipsize="marquee"
自动将“...”添加到已被截断的任何行的末尾:
<TextView
android:id="@+id/txtView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:maxLength="10"
android:ellipsize="marquee"/>