在mutiline TextView的WRAP_CONTENT宽度宽度、mutiline、TextView、WRAP_CONTENT

2023-09-06 04:06:01 作者:港岛少年

我有宽度和高度设置为WRAP_CONTENT和max_lines设置为2。当文字一行适合一个TextView,一切完美的作品。但是,当它换到第二行,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            |

推荐答案

尝试将TextView中的最大宽度。当你设置宽度WRAP_CONTENT我想,它移动到下一行则表示宽度为最大值(所以它填充母containter)。所以我想,当你设置的最大宽度它要到下一行一旦达到这个宽度。

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"