你如何得到一个TextView的文本是正当的(与文本flush在左边和右手边)?
我在这里找到了一个可能的解决方案,但它不起作用(即使您将vertical-center更改为center_vertical等)。
你如何得到一个TextView的文本是正当的(与文本flush在左边和右手边)?
我在这里找到了一个可能的解决方案,但它不起作用(即使您将vertical-center更改为center_vertical等)。
当前回答
Simplay我们可以使用android: justify mode ="inter_word"
<TextView
android:justificationMode="inter_word"
android:id="@+id/messageTv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="@dimen/text_margin"
android:paddingTop="15sp"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
其他回答
你可以在github中使用jusfiedtextview for Android项目。这是一个自定义视图,为您模拟正确的文本。它支持Android 2.0+和从右向左的语言。
TextView在Android O提供了充分的理由(新的排版对齐)本身。 你只需要这样做:
科特林
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
textView.justificationMode = JUSTIFICATION_MODE_INTER_WORD
}
Java
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
textView.setJustificationMode(JUSTIFICATION_MODE_INTER_WORD);
}
XML
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:justificationMode="inter_word" />
默认值是jusication_mode_none (xml中的none)。
Android目前还不支持完全的理由。我们可以使用Webview和证明HTML而不是使用textview。它工作得很好。如果你们不清楚,可以问我:)
在xml文件中使用此属性即可
android:justificationMode="inter_word"
我不认为Android支持完全的理由。
更新2018-01-01:Android 8.0+支持TextView对齐模式。