我一直在研究这个问题,但所有的建议似乎都不起作用。我是 Android 应用程序的新手,虽然答案对于一些人来说可能很简单,但我就是看不出错在哪里......
我有一个 TextView 字段,其中包含一个带有换行符 (\n) 的字符串值。在图形输出中,下方的文本行未居中到 TextView 容器。我的代码如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView5"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp"
android:text="@string/maxText"
android:textAlignment="gravity"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="bold" />
</RelativeLayout>
我的字符串如下:
<string name="maxText">My text part 1:\nMy text part 2</string>
输出文本的下划线左对齐于容器,但我需要它居中。我尝试了所有在论坛等地方找到的建议,但都没有成功。希望能得到帮助。