Eduardo
Eduardo

Reputation: 1199

TextView multiline

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

Upvotes: 4

Views: 11532

Answers (5)

3c71
3c71

Reputation: 4511

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.

Upvotes: 0

Rajesh
Rajesh

Reputation: 2618

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

Upvotes: 0

karan
karan

Reputation: 8843

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

Upvotes: 3

Ionică Bizău
Ionică Bizău

Reputation: 113335

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).

Upvotes: 0

SamSPICA
SamSPICA

Reputation: 1366

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

Upvotes: -1

Related Questions