在 TextView 中按行控制对齐方式

Control justification by lines in TextView

我有 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 居中?

更新:

下面的代码仍未居中 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>"));

你可以将它分成 两个 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>"));