Android 布局文本视图对齐问题

Android 布局文本视图对齐问题,android,xml,android-layout,Android,Xml,Android Layout,我已经尝试了所有的布局,但我仍然有同样的问题。我想水平对齐TextView,但没有任何效果。在所有可用的布局中,没有一个是有效的。总是有相同的图片。就像在右边有一个街区挡住了一切 有人能帮忙吗?试试约束布局 第一个例子: <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schem

我已经尝试了所有的布局,但我仍然有同样的问题。我想水平对齐TextView,但没有任何效果。在所有可用的布局中,没有一个是有效的。总是有相同的图片。就像在右边有一个街区挡住了一切


有人能帮忙吗?

试试约束布局

第一个例子:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView20"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        android:gravity="center"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

第二个例子:

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/textView20"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginEnd="8dp"
        android:layout_marginStart="8dp"
        android:layout_marginTop="8dp"
        android:text="TextView"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>

尝试使用

android:layout_gravity="center_horizontal"
这将告诉Android对齐您的文本视图,使其水平居中对齐

范例

<TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            />


此外,请共享您的xml代码,以便我可以更正它

请将您的xml代码放在此处共享相关代码,在本例中为该活动的布局xml。@未知删除ConstraintLayout并将其替换为LinearLayout,然后它应能与我的建议配合使用,因此请尝试android:Layout\u gravity=“center”