本文介绍了在mutiline TextView的WRAP_CONTENT宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有宽度和高度设置为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"

这篇关于在mutiline TextView的WRAP_CONTENT宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-21 09:50