24

My textview is wrapping text despite the settings lines="1" and ellipsise="end". What do I need to do in addition to prevent the line wrapping hand have the text ellipsised with a "..." as intended?

 <TextView
     android:id="@+id/title"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_toRightOf="@id/date"
     android:background="@color/listHeaderBackground"
     android:ellipsize="end"
     android:gravity="left|center_vertical"
     android:height="30dp"
     android:lines="1"
     android:maxLines="1"
     android:paddingBottom="3dp"
     android:paddingLeft="20dp"
     android:paddingRight="7dp"
     android:paddingTop="3dp"
     android:text="New Ion Beam Etcher ordered blah blah blah blah"
     android:textAppearance="?android:attr/textAppearanceSmall"
     android:textColor="@color/listHeaderForeground" />

see the third item: "New sputter tool" etc. screenshot

Glemi
  • 676
  • 1
  • 7
  • 17
  • **android:scrollHorizontally**: Whether the text is allowed to be wider than the view (and therefore can be scrolled horizontally). Ref. here: http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ascrollHorizontally – Voicu Jul 11 '13 at 22:58

3 Answers3

36

Add the following to your TextView definition:

android:maxLines="1"
Benoit Duffez
  • 11,839
  • 12
  • 77
  • 125
Graham Povey
  • 939
  • 8
  • 8
  • 1
    The global attribute resource symbol `singleLine` is deprecated. – Voicu Jul 11 '13 at 23:02
  • 1
    Good catch - should now use `android:inputType="text"` – Graham Povey Jul 12 '13 at 07:05
  • 1
    This appears to help but I get the following warning now: `Attribute android:inputType should not be used with : Change element type to ?` – Glemi Jul 25 '13 at 21:14
  • That wouldn't be a big deal but I'm not getting the ellipsis ("...") at the end of the textView either. – Glemi Jul 25 '13 at 21:22
  • Fascinating: It works when I use `android:singleLine="true"` although the fact that it's deprecated is disturbing. What I don't understand is why there is no mention of this here http://developer.android.com/reference/android/widget/TextView.html#attr_android:singleLine but only here (http://developer.android.com/reference/android/R.attr.html#singleLine). They tell you to use maxLines instead but as you can see that did **not** help in my case. – Glemi Jul 25 '13 at 21:49
  • As of Android SDK Build-tools 21.1, `singleLine` does not warn about deprecation, whereas `inputType` does cause a warning. – Edward Brey Oct 31 '14 at 22:40
9

The option shown below is deprecated

android:singleLine="true"

Instead use this:

android:maxLines="1"
mattfred
  • 2,689
  • 1
  • 22
  • 38
1

From TextView Ellipsize (...) not working :

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

And in your style.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>
Community
  • 1
  • 1
invertigo
  • 6,336
  • 5
  • 39
  • 64