4

I have a TextView that is populated with a text that is taken from a database, so its lenth is undefined.

I have configured the TextView using the maxline attribute, and I have set its value to 3, because I don't want more than 3 lines of text, and also I use the ellipsize attribute.

But It doesn't work properly. Although the text is larger than 3 lines, it only prints two lines.

<TextView
    android:id="@+id/etLugar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignBaseline="@+id/tvLugar"        
    android:layout_marginLeft="15dp"
    android:layout_toRightOf="@+id/tvLugar"
    android:text="A very large text than must be shown in the textview, but no more of three lines are going to be shown"
    android:textColor="@color/foreground1"        
    android:maxLines="3"
    android:ellipsize="end"        
    android:textSize="12dp" 
    />

I don't understand why maxlines attribute is is not working properly. What I'm doing wrong?

Thanks

Eduardo
  • 1,169
  • 5
  • 21
  • 56

5 Answers5

3

i guess it is due to android:singleLine="false" which is default value try and change it to TRUE tell if it works.

karan
  • 8,637
  • 3
  • 41
  • 78
0

There is same question Android ellipsize multiline textview. This is known bug, quite old and not fixed yet.

Someone posted workaround Android Textview Multiline Ellipse/ maybe it will help you (or someone else).

Community
  • 1
  • 1
Ionică Bizău
  • 109,027
  • 88
  • 289
  • 474
  • Hello, I've tried the solution I've read in the question you told me, but it doesn't work. Again, two lines but now it is not ellipsed... – Eduardo Jul 20 '12 at 11:48
0

Because of you have less content that has two line only, it was work perfectly which you wrote code(xml) enter more content in string then try it.

image enter image description here

Rajesh
  • 2,618
  • 19
  • 25
0

I'm having a similar issue with 2 TextView, one is supposed to have maxLines="2" and the other maxLines="4".

The first was always on a single line, regardless of the ellipsize setting I add. The second didn't matter and text was using as many lines it needed!

It seems to depends on 2 factors:

  1. The other elements of your layout
  2. The textAppearance if set may break/override this setting or a singleLine option

To solve this I added code to do that directly on the text views:

tv1.setMaxLines(2);
tv2.setMaxLines(4);

And that did the trick.

3c71
  • 4,313
  • 31
  • 43
-1

Don't use the ellipsize attribute, just android:maxlines="3" should work.

Abdul Rahman
  • 2,097
  • 4
  • 28
  • 36
SamSPICA
  • 1,366
  • 15
  • 31
  • 1
    Ok, it works, three line are shown, but now the ellipse is not shown – Eduardo Jul 20 '12 at 12:13
  • Are you using default font or custom. I ran into this and the ellipse was not defined in the font so it ended up drawing a space. – JPM Aug 12 '14 at 20:50
  • For whatever I did, it was the default font. Never tried with other fonts, but that should not matter, if I'm not wrong. – SamSPICA Aug 15 '14 at 07:48