Android Tablelayout中的按钮未居中

Android Tablelayout中的按钮未居中,android,android-linearlayout,Android,Android Linearlayout,我有一个线性布局内的表格布局。 在我的桌面布局中,我有一些按钮。 我希望包括按钮在内的所有内容都居中,因此我添加了行android:gravity=“center\u horizontal” 不幸的是,按钮不能居中,我不明白为什么会这样 我的代码是: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xm

我有一个线性布局内的表格布局。 在我的桌面布局中,我有一些按钮。 我希望包括按钮在内的所有内容都居中,因此我添加了行
android:gravity=“center\u horizontal”

不幸的是,按钮不能居中,我不明白为什么会这样

我的代码是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
android:padding="10dp"
android:gravity="center_horizontal"
tools:context="com.example.standard.quizzza.MainActivity">

<TextView
    android:id="@+id/frage"
    android:layout_width="wrap_content"
    android:layout_height="60sp"
    android:layout_marginBottom="5dp"
    android:text="Hello World!"
    android:textStyle="bold"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<TableLayout
    android:layout_width="match_parent"
    android:layout_height="110dp"
    android:gravvity="center">

    <TableRow
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/antwortA"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="Antwort A" />

        <Button
            android:id="@+id/antwortB"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="Antwort B" />
    </TableRow>

    <TableRow
        android:layout_width="150dp"
        android:layout_height="match_parent">

        <Button
            android:id="@+id/antwortC"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="Antwort C" />

        <Button
            android:id="@+id/antwortD"
            android:layout_width="150dp"
            android:layout_height="wrap_content"
            android:text="Antwort D" />
    </TableRow>

</TableLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="136dp"
    android:orientation="vertical">

    <TextView
        android:id="@+id/textView"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/progressBar"
        android:background="@android:color/transparent"
        android:gravity="center"
        android:text="Frage 1 von 8" />

    <ProgressBar
        android:id="@+id/progressBar"
        style="?android:attr/progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:max="8"
        android:progress="1" />


</LinearLayout>
</LinearLayout>

标记中添加
android:gravity=“center”
,并使宽度与父项匹配

由于您使用了
宽度
包裹内容
,因此没有额外的空间可供视图居中


希望这会有所帮助。

尝试将“重力”更改为“重力”,并对表行使用“换行内容”而不是“匹配父项”