TextView Ellipsize (…) not working

后端 未结 6 2061
醉梦人生
醉梦人生 2020-12-29 20:55

I want to have a single lined TextView to show up 3 dots at the end when the text is longer than the TextView. I don\'t know why - but I don\'t get

相关标签:
6条回答
  • 2020-12-29 21:17

    The ellipses did not appear while my text was selectable. I needed to disable selectable text (which is the default):

    android:layout_width="0dp" (match constraint)
    android:layout_height="wrap_content"
    android:ellipsize="end"
    android:maxLines="1"
    android:textIsSelectable="false"
    
    0 讨论(0)
  • 2020-12-29 21:20

    This doesn't work with me unless adding 'android:ems' attribute along with the android:ellipsize attribute

    android:ellipsize="end"
    android:singleLine="true"
    android:ems="8"
    
    0 讨论(0)
  • 2020-12-29 21:37

    Add this in your xml for the TextView:

            android:maxWidth="200dp" 
            android:maxLines="1" 
    

    As

            android:singleLine="true"  
    

    is deprecated.

    0 讨论(0)
  • 2020-12-29 21:39

    Add the following styles in your styles file (typically styles.xml):

    <style name="autoscroll">
        <item name="android:singleLine">true</item>
        <item name="android:ellipsize">marquee</item>
        <item name="android:marqueeRepeatLimit">marquee_forever</item>
        <item name="android:focusable">true</item>
        <item name="android:focusableInTouchMode">true</item>
        <item name="android:scrollHorizontally">true</item>
    </style>
    

    Then add the style @style/autoscroll to your TextView:

    <TextView android:id="@+id/lName"
          style="@style/autoscroll" />
    

    You can reuse your autoscroll feature easily when you want this way.

    0 讨论(0)
  • 2020-12-29 21:41
    android:id="@+id/lName" android:layout_width="150dp"
        android:layout_height="wrap_content"
        android:ellipsize="end"
        android:singleLine="true"
        android:text="Avinljhakjhsajkhakjshda"
        android:textSize="16sp"
    
    0 讨论(0)
  • 2020-12-29 21:42

    It works with singleLine="true" but this attribute is now deprecated, use ellipsize and scrollHorizontally="true" instead.

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