我有TextView:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MY TITLE\n\n
first line.................................................... \n
second line.................................................... \n
third line.................................................... \n"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/title" />
这会带来左对齐文本:
如何仅使文本MY TITLE
的第一行居中?
UPD:
下面的代码仍不能居中MY TITLE
字符串:
t.setText(Html.fromHtml("<h><center>MY TITLE</center></h>\n" +
"<p>first line....................................................</p> </br>\n" +
"<p>second line....................................................</p> </br>\n" +
"<p>third line....................................................</p> </br>"));
答案 0 :(得分:1)
U可以将其分隔为两个TextView ,也可以使用 Html.fromHtml
t.setText(Html.fromHtml("<div style='text-align:center' >MYTITLE</center></div>\n" +
"<p>first line....................................................</p> </br>\n" +
"<p>second line....................................................</p> </br>\n" +
"<p>third line....................................................</p> </br>"));