android:single和android:maxLines的区别

android:singleLine="true"

android:lines="1"

android:maxLines="1"

都可以保证控件只显示一行,但他们还是有区别的

android:singleLine

Constrains the text to a single horizontally scrolling line instead of letting it wrap onto multiple lines, and advances focus instead of inserting a newline when you press the enter key. The default value is false (multi-line wrapped text mode) for non-editable text, but if you specify any value for inputType, the default is true (single-line input field mode).


android:maxLines

Makes the TextView be at most this many lines tall. When used on an editable text, the inputType attribute's value must be combined with the textMultiLine flag for the maxLines attribute to apply.

android:lines

Makes the TextView be exactly this many lines tall.

maxLines 是在限制高度, singleLine 是强制不让换行。具体效果有什么区别呢? 从高度来讲是一样的,两者肯定都显示一行,但从换行的位置来讲就有区别了,maxLines并不会改变其换行的位置,而singleLine则会。从这个角度讲,singleLine的显示会好一些,因为如果超过一行singleLine会在一行内显示,后面加上"...",而maxlines="1" 则不会,它依然会在原来换行的位置换行,所以有时候一行不满,但是却不显示剩下的部分。

对比下:(Text 的内容为:新建文件夹qqqqqqqqqqqqqqqqqqqqqqqq

maxLines = “1”  或lines = “1”显示: 



singleLine=“true" 显示:



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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值