我有这样的布局(我已经删除某些属性,因为他们真的没关系,完全示范项目是here):TextView的工作错breakStrategy =“平衡”和layout_width =“WRAP_CONTENT”
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content" (* this is important)
android:layout_height="wrap_content"
android:breakStrategy="balanced" (* this is important)
android:text="@string/long_text" />
</LinearLayout>
文本long_text
很长,所以它会分开几行。
两条重要线是android:layout_width="wrap_content"
和android:breakStrategy="balanced"
。
我预计TextView
会根据实际的文本宽度计算宽度,但它不会。
是否有人知道如何解决这一问题?
UPDATE
属性android:breakStrategy="balanced"
仅适用于API 23
高。在我的示例中,文本需要3行,而balanced
策略使每行大致相同的宽度。
我预计在这种情况下,视图本身的宽度将与最长的一行相同。
我正在寻找任何解决方法。我需要像环聊聊天中的解决方案。我无法弄清楚它是如何工作的。
更新2
不幸的是,公认的答案并不与RTL文本。
怎么办你的意思是'我希望TextView会根据实际的文本宽度来计算宽度,但它不会' Als o你的实际看起来与本应该[像这样]不同(https://imagebin.ca/v/38OTigaIafpF) – shadygoneinsane
我已更新问题。 –
@Oleksii Kropachov如果你期望突破线条,可以说它比1.5线更长..所以你的预期输出是什么? –