android:maxLines="1"截取显示不全,用android:singleLine="true"解决

来源:互联网 发布:折800被淘宝封了 编辑:程序博客网 时间:2024/04/30 01:23

问题描述:

1. android:maxLines="1", 只显示一个中文

 

2. android:singleLine="true", 正常显示

 

问题原因:

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. 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 1
  • 2
  • 3
  • 4
  • 5

具体区别:

       android:maxLines是限制高度,android:singleLine是强制不让换行。从高度上来讲二者是一样的,都只显示了一行字串, 但从换行的角度来讲,android:maxLines并不会改变换行的位置,而android:singleLine则会改变换行的位置所以,如果要截取字符串并追加省略号显示,尽量用android:singleLine属性。如果要控制显示行数,尽量用android:maxLines属性。

0 0
原创粉丝点击