zl程序教程

您现在的位置是:首页 >  其他

当前栏目

跑马灯效果的TextView之singLine 和maxLines详解编程语言

编程语言 详解 效果 textview 跑马灯
2023-06-13 09:20:39 时间

 Android 的TextView 里面有两个属性 singLine 和maxLines 。 从字面意思来理解,这两个都是限制Text的行数。那么singleLine= true 和maxLine= 1 都是限制为一行,有什么区别呢?

    先看看Google Document 的解释:

   
android:maxLines   Makes the TextView be at most this many lines tall. 

   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. 

 

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

 

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

maxLines = “1”  显示: 

 

跑马灯效果的TextView之singLine 和maxLines详解编程语言

 

singleLine=“true 显示:

 

跑马灯效果的TextView之singLine 和maxLines详解编程语言

原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/13433.html

cgowindows