wrap_content width on mutiline TextView

2020-06-09 06:52发布

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            |

1条回答
够拽才男人
2楼-- · 2020-06-09 07:36

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"
查看更多
登录 后发表回答