在Android中,如果长度大于某个限制,我怎么能通过在文本的末尾放置三个点来限制TextView的宽度?
答案 0 :(得分:10)
将此代码放入TextView
android:ellipsize="end"
android:singleLine="true" // if you want 3 dots for single line, add this.
android:maxLines="2" // if you want 3 dots after two lines, add this.
答案 1 :(得分:1)
为此目的使用ellipsize属性。
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/text_mytext"
android:ellipsize="end"
android:singleLine="true"
/>
与上述类似的代码应该适合您。同时设置maxLines=1
。