如何在 Android 中对齐 TextView 的文本

Hus*_*lam 3 xml textview

希望你一切顺利

我想将我的文本对齐TextView

有没有办法做到这一点?

提前致谢

小智 6

XML 布局:声明 WebView 而不是 TextView

<WebView
 android:id="@+id/textContent"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content" />
Run Code Online (Sandbox Code Playgroud)

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");
Run Code Online (Sandbox Code Playgroud)

这可能会解决您的问题。