Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wrap_content width on mutiline TextView

I have a TextView with both width and height set to wrap_content and max_lines set to 2. When text fits in one line, everything works perfectly. But when it wraps to the second line, TextView's width becomes as big as possible (it fills parent container).
So, what I want:

    |Some Long|
    |Text     |
And what I get:
    |Some Long       |
    |Text            |
like image 660
Grishka Avatar asked Nov 09 '11 18:11

Grishka


1 Answers

Try setting the max width of the TextView. I think when you set the width wrap_content and it moves on to the next line it means the width is at its maximum (so it fills parent containter). So I guess when you set the max width it has to go to the next line once it reaches this width.

 android:maxWidth="140dp"
like image 98
Jap Mul Avatar answered Oct 26 '22 22:10

Jap Mul