限制的TextView的长度 [英] Limit the Length of TextView
本文介绍了限制的TextView的长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
的EditText在Android的 限制文本长度
我是一个TextView的活动,目前正在显示按它从JSON响应接收的参数,我需要把它限制在12个字符而已。
<的TextView
机器人:ID =@ + ID / textViewName
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / includeheadersetting
机器人:layout_marginLeft =20dp
机器人:layout_marginTop =20dp
机器人:重力=中心
机器人:文本=名称
机器人:文字颜色=#000000
机器人:TEXTSTYLE =黑体/>
解决方案
使用 Android版本:最大长度=12
文本长度的限制
<的TextView
机器人:ID =@ + ID / textViewName
机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_below =@ + ID / includeheadersetting
机器人:layout_marginLeft =20dp
机器人:layout_marginTop =20dp
机器人:重力=中心
机器人:文本=名称
机器人:最大长度=12
机器人:文字颜色=#000000
机器人:TEXTSTYLE =黑体/>
您也可以使用其他财产一样为
安卓ellipsize =终结
机器人:单线=真
使用此属性的...将被添加文本的结尾像
你好,...而不是你好,你好吗?
Possible Duplicate:
Limit text length of EditText in Android
I am a textView on Activity, which is being displayed as per the parameter it is receiving from the JSON response, I need to restrict it to 12 characters only.
<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" />
解决方案
Use android:maxLength="12"
for limit of text length
<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" />
You can also use other property like as
android:ellipsize="end"
android:singleLine="true"
using this property "..." will be added end of the text like
"Hello How are ..." instead of "Hello How are you?"
这篇关于限制的TextView的长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文