android:TextView单行显示设定字符长度,超过后面为省略号

在 TextView 中加入:

    (注意:layout_width="wrap_content",宽度必须是wrap_content,为match_parent无效)

    android:maxEms="10"   //限制字节长度为10

    android:ellipsize="end"  //省略号在最后面

    android:singleLine="true" //超过长度10为省略号

即可;如:

<TextView
    android:textSize="18dp"
    android:text="计费的手机看撒即可杰卡斯发送到"
    android:padding="20dp"
    android:singleLine="true"
    android:maxEms="10"
    android:ellipsize="end"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />


下面的方法是 TextView 字数很长,显示不下的让它后面自动为省略号:

                        android:maxWidth="140dp"
                        android:ellipsize="end"

                        android:singleLine="true"

        重要的是 android:maxWidth="140dp" 指定长度,超过长度后面自动为省略号。


猜你喜欢

转载自blog.csdn.net/weixin_40350174/article/details/81063544