您是否尝试过XML中的minLines?
类似这样:
<TextView
android:id="@+id/tv_previous_story"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="3dp"
android:minLines="2" //(could be any minimum amount of lines)
android:textColor="@color/text_color"
android:textSize="@dimen/privacy_text_size" />
如果您始终至少有两个单词(或您在XML中设置的最小行数),这对您应该很好,...
如果不是您要搜索的内容,也许您可以以编程方式处理它,并根据单词数设置TextView的宽度和高度...不是确切的方法,例如:
void updateWidthAndHeightOfTextView(TextView tv, String t) {
tv.setWidth(t.length * [bla bla bla]);
tv.setHeight(tv.getWidth() / [bla bla bla]); //(if you want to change the height too, in this case according to the width)
}
您以自己的方式编写,知道您的需求...
而且,还有this个答案,我实际上并不熟悉,但也可能会回答您的需求...
此外,下次请提出更具体的问题,这样人们就不必费力地试图了解如何为您提供所需的相关答案
希望对您有帮助!