10.Texview或EditText设置长度控制显示省略号

1.设置 maxEms

如果TextView后面有其他控件,需要注意是否会被TextView控件挤掉(设置maxLength达不到这个效果,maxLength不会自动显示省略号)

1.   android:ellipsize="end"  

2.   android:maxEms="7"  

3.   android:singleLine="true"  


2.设置 layout_width为固定长度

<TextView
    android:id="@+id/tv_content"
    android:layout_width="200"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:text="如果伟大复兴是一场考试,那定是一场关乎中国民族前途命运的巨大考验如果伟大复兴是一场考试,那定是一场关乎中国民族前途命运的巨大考验如果伟大复兴是一场考试,那定是一场关乎中国民族前途命运的巨大考验。"
    android:textColor="@color/gray9"
    android:textSize="14sp"
    android:maxLines="3"
    android:ellipsize="end"/>

猜你喜欢

转载自blog.csdn.net/lanxuan1993/article/details/80354039