Text does not ellipsize

前端 未结 13 1350
隐瞒了意图╮
隐瞒了意图╮ 2020-12-25 11:43

I have a TextView set to ellipsize but when I put the text in it doesn\'t do so. Any ideas?



        
相关标签:
13条回答
  • 2020-12-25 12:21

    You change your layout_width to certain dp instead of wrap_content

    and

    use
    android:singleLine="true"

    android:ellipsize="end"

    code:

        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:text="check this text"
        android:id="@+id/textView"
        android:singleLine="true"
        android:ellipsize="end"/>
    
    0 讨论(0)
  • 2020-12-25 12:24

    You need to match the settings for android can correctly calculate the position of the object. Has several possible combinations, and depends on the rest of the layout is on the same line.

    This is a combination that works:

    android:layout_width="0dip" // dynamic width
    android:layout_weight="1"   // less weight, other objects still "0"
    android:ellipsize="end"     // ... into end of text (right)
    android:singleLine="true"   // one line, deprecated, but necessary for some ambients
    android:maxLines="1"        // one line, new mode
    

    In summary, you indicate the weight, if you use dynamic layout, or just a fixed size, then indicates to only have one line and configures how "..." is displayed.

    0 讨论(0)
  • 2020-12-25 12:30

    This solution works:

    android:ellipsize="end"
    android:singleLine="false"
    android:lines="3"
    android:maxLines="3"
    

    Width can also be set to "wrap_content"

    0 讨论(0)
  • 2020-12-25 12:31

    My app started ignoring maxlines & ellipsize when I added

    android:textIsSelectable="true"
    

    It seems like these options are not compatible together.

    0 讨论(0)
  • 2020-12-25 12:34

    If you aren't defining a specific width for your TextView the text will ellipsize first when your text is reaching the parent view's width.

    0 讨论(0)
  • 2020-12-25 12:35

    Try:

    android:singleLine="true"
    
    0 讨论(0)
提交回复
热议问题