End TextView with 3 dots with use of maxLength

前端 未结 11 811
北海茫月
北海茫月 2020-12-13 06:08

I have a TextView in my layout which is wrap_content in layout_width. It is limited to maximum of 15 characters so I\'m using maxLength.

I need to end this TextView

相关标签:
11条回答
  • 2020-12-13 06:09

    You can just modify the String when it's length is above 20 to add the ellipsize.

    0 讨论(0)
  • 2020-12-13 06:09

    Very Important: ellipsize = "end" only works when maxLength is set to a value that is more than the number of characters on one line. You can use wrap_content if you align the TextView's end and start to any other view(s).

    0 讨论(0)
  • 2020-12-13 06:13

    use this android:ellipsize="end"

    0 讨论(0)
  • 2020-12-13 06:16

    remove the line from xml

    android:lines="1"
            android:maxLines="1"
    
    0 讨论(0)
  • 2020-12-13 06:17

    You cannot use both maxLength and Ellipsize although you can define Maximum EMS see the example below

    <TextView
            android:id="@+id/tv_hist_source_lang"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ellipsize="end"
            android:maxEms="8"
            android:maxLines="1"
            android:text="TextView"
            android:textAppearance="?android:attr/textAppearanceMedium" />
    

    It looks like this

    0 讨论(0)
  • 2020-12-13 06:21

    You can use

    android:maxWidth="100dp"
    android:maxLines="1"
    android:ellipsize="end"
    

    Only this works for me.

    0 讨论(0)
提交回复
热议问题