TextView cuts off text when it is long enough

后端 未结 6 1359
执笔经年
执笔经年 2021-01-31 11:16

I have strange problem with TextView, it cuts off part of the text at the end. My layout looks like



        
相关标签:
6条回答
  • 2021-01-31 11:35

    Make use of these attributes

        android:lines="1"
        android:scrollHorizontally="true"
        android:ellipsize="end"
    

    will append "..." at the end. But this will not solve problem in honeycomb tab

    So for honeycomb tablet add the following atttibute also

    android:singleLine="true" 
    

    On the other hand if you require marquee effect

    android:singleLine="true"
    android:ellipsize="marquee" 
    android:marqueeRepeatLimit="marquee_forever"
    android:scrollHorizontally="true" 
    android:focusable="true" 
    android:focusableInTouchMode="true
    
    0 讨论(0)
  • 2021-01-31 11:39

    If you expect differing lengths of text for your view or you're going to change the textSize of different instances of your TextView then you should use View.addOnLayoutChangeListener().

    See an example here: https://stackoverflow.com/a/44069734/1402087

    0 讨论(0)
  • 2021-01-31 11:42

    Yes there are some attributes you need to set, but first let us know what type of textview do you want exactly, single line or multi line?

    There are some attributes you can take care of:

    android:singleLine="true"  // or false
    android:ellipsize="marquee"   // must check
    android:lines="1"
    
    0 讨论(0)
  • 2021-01-31 11:45

    You need to set android:minLines="2"

    0 讨论(0)
  • 2021-01-31 11:52

    Set below properties in layout file. It works fine for me

    android:singleLine="true"
    android:ellipsize="marquee"
    android:marqueeRepeatLimit="marquee_forever"
    android:focusableInTouchMode="true"
    
    0 讨论(0)
  • 2021-01-31 11:53

    For me it I realised I was using the layout view of a different device to the one I was testing with. When I corrected this, I could see the textlayout was way too wide so I used this setting to reign it in:

    android:layout_width="330dp"
    
    0 讨论(0)
提交回复
热议问题