无法对齐相对和线性布局中的图像按钮

Unable to align image buttons inside relative and linear layout

我想在第一行有 3 个图像按钮,在第二行有 3 个图像按钮。 我尝试结合相​​对布局和线性布局来实现它,但不知何故,我最终每行有 1 个图像按钮,总共有 6 行。

谁能帮我对齐第一行的 3 个图像框和第二行的 3 个图像框。

<FrameLayout 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"
    tools:context="app.com.date.design.drawer.AddImagesFragment">

    <!-- TODO: Update blank fragment layout -->

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/layout1"
            android:baselineAligned="false"
            android:orientation="vertical">

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/common_full_open_on_phone"
                android:id="@+id/image1" />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/common_full_open_on_phone"
                android:id="@+id/image2" />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/common_full_open_on_phone"
                android:id="@+id/image3" />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/common_full_open_on_phone"
                android:id="@+id/image4" />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/common_full_open_on_phone"
                android:id="@+id/image5" />

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:srcCompat="@drawable/common_full_open_on_phone"
                android:id="@+id/image6"
                android:layout_weight="0.05" />
        </LinearLayout>

    </RelativeLayout>

</FrameLayout>

试试这个代码,

activity_main.xml :

<RelativeLayout 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:id="@+id/activity_main"
    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">

    <LinearLayout
        android:id="@+id/lin1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="3">

        <ImageButton
            android:id="@+id/image1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/star2" />

        <ImageButton
            android:id="@+id/image2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/star1" />

        <ImageButton
            android:id="@+id/image3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/star3" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/lin2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/lin1"
        android:orientation="horizontal"
        android:weightSum="3">

        <ImageButton
            android:id="@+id/image4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/star2" />

        <ImageButton
            android:id="@+id/image5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/star1" />

        <ImageButton
            android:id="@+id/image6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            app:srcCompat="@drawable/star3" />

    </LinearLayout>


</RelativeLayout>

特此附上截图,

希望对您有所帮助。