如何在Android中将TextView的文本对齐

3

希望你一切都好。

我想在TextView中对齐我的文本,有没有什么办法可以做到这一点?

谢谢您的帮助。


可能重复 https://dev59.com/tV3Va4cB1Zd3GeqPBIA9#9755219 - Josef E.
2个回答

6

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");

这可能会解决你的问题。

2

我使用这个项目来调整文本。它在我的项目中运行良好。JustifiedTextView

XML代码

<com.codesgood.views.JustifiedTextView
    android:padding="3dp"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:text="@string/card_use_hint"/>

结果

文本两端对齐


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接