你如何得到一个TextView的文本是正当的(与文本flush在左边和右手边)?

我在这里找到了一个可能的解决方案,但它不起作用(即使您将vertical-center更改为center_vertical等)。


当前回答

XML布局:声明WebView而不是TextView

<WebView
 android:id="@+id/textContent"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />

Java代码:设置文本数据到WebView

WebView view = (WebView) findViewById(R.id.textContent);
String text;
text = "<html><body><p align=\"justify\">";
text+= "This is the text will be justified when displayed!!!";
text+= "</p></body></html>";
view.loadData(text, "text/html", "utf-8");

这也许能解决你的问题。 它完全为我工作。

其他回答

我不认为Android支持完全的理由。

更新2018-01-01:Android 8.0+支持TextView对齐模式。

虽然仍然不是完整的文本,你现在可以平衡行长度使用android:breakStrategy="balanced"从API 23起

http://developer.android.com/reference/android/widget/TextView.html#attr_android:breakStrategy

非常简单的 我们可以在xml文件中这样做

<TextView 
android:justificationMode="inter_word"
/>

我写了一个基于本地textview的小部件来做到这一点。

github

Android目前还不支持完全的理由。我们可以使用Webview和证明HTML而不是使用textview。它工作得很好。如果你们不清楚,可以问我:)