Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/216.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 文本视图中的文本水平居中不工作_Android_Xml_Android Layout_Android Studio - Fatal编程技术网

Android 文本视图中的文本水平居中不工作

Android 文本视图中的文本水平居中不工作,android,xml,android-layout,android-studio,Android,Xml,Android Layout,Android Studio,这听起来可能很愚蠢,但我正在努力解决这个问题,所以请耐心等待 因此,我有一个简单的TextView,我想在屏幕中居中显示: <TextView android:id="@+id/helloTextView" android:layout_width="wrap_content" android:layout_height="wrap_content" android:gravity="center" android:includeFontPaddin

这听起来可能很愚蠢,但我正在努力解决这个问题,所以请耐心等待

因此,我有一个简单的
TextView
,我想在屏幕中居中显示:

<TextView
    android:id="@+id/helloTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:includeFontPadding="false"
    android:text="Hello!"
    android:textSize="50sp"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.5"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.464" />

我用
wrap\u content
match\u constraint
进行了尝试,但未能将其置于中心位置。当我
包装内容时
框正确居中,但其中的文本与您在此处看到的不同:

当我匹配约束时,它只是垂直居中,而不是水平居中:


我错过了什么?

在您发布的文本视图的xml中添加:

android:textAlignment="center"

在您发布的文本视图的xml中添加:

android:textAlignment="center"

你能提供一个完整的例子和简要的解释吗?你能提供一个完整的例子和简要的解释吗?