android maxlength 汉字,Android:TextView maxWidth maxLines maxLength maxEms

TextView

maxWidth、maxLines、maxLength、maxEms 的区别面纱就此揭开!掌握它们的区别对实际开发蛮有用处。若您有遇到其它相关问题。

maxWidth

限制当前view的宽度,若此时高度设置为wrap_content,文字长度超过view的宽度时会自动换行

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#3E86A0"

android:textColor="#ffffff"

android:text="TextView_maxWidth"

android:maxWidth="50dp"/>

12645f4ed215c1d2b810ddc6312ec3b7.png

maxLines

无论文字整体需要几行才可显示,最终只显示 N 行。一般配合ellipsize标签使用,它可指定在尾部添加省略号

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#3E86A0"

android:textColor="#ffffff"

android:text="TextView_maxWidthTextView_maxWidthTextView_maxWidth"

android:ellipsize="end"

android:maxLines="1"/>

a969c9d52fd1713f4303f326c6799cdf.png

maxLength

限制可显示字符数量,超出部分会被截断,设置 ellipsize 也无效,字母或汉字每个单位均记做1,

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#3E86A0"

android:textColor="#ffffff"

android:text="TextView_maxWidth"

android:ellipsize="end"

android:maxLength="5"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#3E86A0"

android:textColor="#ffffff"

android:text="测试这个标签的作用"

android:ellipsize="end"

android:maxLength="5"/>

9ef39a04f56f7f38f06b484adcbe859b.png

maxEms

单行最多可现实的字符数量,超出限制自动换行,汉字记做2个单位,字母记做1个单位

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#3E86A0"

android:textColor="#ffffff"

android:text="TextView_maxWidth"

android:maxEms="5"/>

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:background="#3E86A0"

android:textColor="#ffffff"

android:text="测试这个标签的作用"

android:maxLines="1" // 这里设置了行数限制,所以下图中的文字被截取

android:maxEms="5"/>

e4b6e35a69bb186cafe7672286868687.png

若您有遇到其它相关问题,非常欢迎在评论中留言。

bbfa93c08e2b1bc0effbc1edef0ed912.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值