- 首先TextView的android:layout_width屬性必須設(shè)置為wrap_content,如果設(shè)置match_parent則不起作用因為TextView的長度已經(jīng)超過了顯示的字符串的長度
- 設(shè)置maxEms屬性限制顯示的長度,
注意:不是設(shè)置maxLength屬性,設(shè)置android:ellipsize屬性設(shè)置省略號的顯示位置 - 設(shè)置限制單行顯示, 通過android:lines="1"屬性或android:maxLines="1"都可以
- 以上屬性都設(shè)置后就能實現(xiàn)想要的效果了,
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginLeft="@dimen/dp_15"
android:layout_marginRight="@dimen/dp_15"
android:maxEms="5"
android:ellipsize="end"
android:lines="1"
android:maxLines="1"
android:text="此處是限制字符長度,顯示省略號的示例"/>
文章來源地址http://www.zghlxwxcb.cn/news/detail-619196.html
文章來源:http://www.zghlxwxcb.cn/news/detail-619196.html
到了這里,關(guān)于TextView限制長度,顯示省略號的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!