简体   繁体   中英

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 | \n    |Text |  

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"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM