Java 设计难度大,为重叠图像按钮以上两个相对布局

Java 设计难度大,为重叠图像按钮以上两个相对布局,java,android,android-layout,android-imagebutton,Java,Android,Android Layout,Android Imagebutton,我正在开发一个应用程序,对于它的设计,我需要像重叠的ImageButton一样在两个相对的布局上面,或者它需要是哪个布局 下面是我实现的设计 <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" a

我正在开发一个应用程序,对于它的设计,我需要像重叠的ImageButton一样在两个相对的布局上面,或者它需要是哪个布局

下面是我实现的设计

<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/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">


<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="229dp"
    android:layout_above="@+id/relative_middle"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginStart="0dp"
    android:layout_marginTop="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="1dp"
    android:background="@drawable/layout_back"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">



</RelativeLayout>

<RelativeLayout
    android:id="@+id/relative_middle"
    android:layout_width="match_parent"
    android:layout_height="323dp"
    android:layout_above="@+id/relativeLayout_base"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="0dp"
    android:background="@drawable/layout_back_white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout"
    app:layout_constraintVertical_bias="0.0"
    tools:ignore="MissingConstraints">

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="117dp"
        android:layout_above="@+id/linearLayout2"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:layout_marginBottom="-19dp"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout2"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/linearLayout2"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

        <androidx.cardview.widget.CardView
            android:layout_width="110dp"
            android:layout_height="110dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:focusable="true"
            android:foreground="?android:attr/selectableItemBackground">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circleshape"
                    android:padding="10dp"
                    android:src="@drawable/settings" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Add"
                    android:textStyle="bold" />


            </LinearLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="110dp"
            android:layout_height="110dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:focusable="true"
            android:foreground="?android:attr/selectableItemBackground">

            // there are some codes here.

        </androidx.cardview.widget.CardView>

    </LinearLayout>

</RelativeLayout>

<RelativeLayout
    android:id="@+id/relativeLayout_base"
    android:layout_width="match_parent"
    android:layout_height="113dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="3dp"
    android:background="@drawable/layout_back"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.888"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relative_middle"
    app:layout_constraintVertical_bias="0.962">

</RelativeLayout>

下面是我实现的设计的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/ll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#fff"
android:gravity="center"
android:orientation="vertical"
android:padding="10dp"
tools:context=".MainActivity">


<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="229dp"
    android:layout_above="@+id/relative_middle"
    android:layout_alignParentStart="true"
    android:layout_alignParentTop="true"
    android:layout_alignParentEnd="true"
    android:layout_marginStart="0dp"
    android:layout_marginTop="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="1dp"
    android:background="@drawable/layout_back"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent">



</RelativeLayout>

<RelativeLayout
    android:id="@+id/relative_middle"
    android:layout_width="match_parent"
    android:layout_height="323dp"
    android:layout_above="@+id/relativeLayout_base"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="0dp"
    android:background="@drawable/layout_back_white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relativeLayout"
    app:layout_constraintVertical_bias="0.0"
    tools:ignore="MissingConstraints">

    <LinearLayout
        android:id="@+id/linearLayout4"
        android:layout_width="match_parent"
        android:layout_height="117dp"
        android:layout_above="@+id/linearLayout2"
        android:layout_alignParentTop="true"
        android:layout_marginTop="40dp"
        android:layout_marginBottom="-19dp"
        android:clipToPadding="false"
        android:gravity="center"
        android:orientation="horizontal"
        app:layout_constraintEnd_toEndOf="@+id/linearLayout2"
        app:layout_constraintHorizontal_bias="1.0"
        app:layout_constraintStart_toStartOf="@+id/linearLayout2"
        app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

        <androidx.cardview.widget.CardView
            android:layout_width="110dp"
            android:layout_height="110dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:focusable="true"
            android:foreground="?android:attr/selectableItemBackground">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:gravity="center"
                android:orientation="vertical">

                <ImageView
                    android:layout_width="64dp"
                    android:layout_height="64dp"
                    android:background="@drawable/circleshape"
                    android:padding="10dp"
                    android:src="@drawable/settings" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="10dp"
                    android:text="Add"
                    android:textStyle="bold" />


            </LinearLayout>
        </androidx.cardview.widget.CardView>

        <androidx.cardview.widget.CardView
            android:layout_width="110dp"
            android:layout_height="110dp"
            android:layout_margin="10dp"
            android:clickable="true"
            android:focusable="true"
            android:foreground="?android:attr/selectableItemBackground">

            // there are some codes here.

        </androidx.cardview.widget.CardView>

    </LinearLayout>

</RelativeLayout>

<RelativeLayout
    android:id="@+id/relativeLayout_base"
    android:layout_width="match_parent"
    android:layout_height="113dp"
    android:layout_alignParentStart="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentBottom="true"
    android:layout_marginStart="0dp"
    android:layout_marginEnd="0dp"
    android:layout_marginBottom="3dp"
    android:background="@drawable/layout_back"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.888"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/relative_middle"
    app:layout_constraintVertical_bias="0.962">

</RelativeLayout>

//这里有一些代码。

现在这个设计显示了一些问题,比如,相对布局不适合屏幕大小

我正在使用dpi drawables为所有设备实现此设计

我的问题是

1。如何实现两个相对布局上方重叠的ImageButton?

2。如何实现适合所有设备的设计?


谢谢

您可以使用浮动按钮,或者当您想在其他视图上显示某些视图时,将这两个视图都放在框架布局中
FrameLayout
最后一个视图的视图将位于其他视图之上。 欲知详情

我建议寻找FloatingActionButton示例,它会有所帮助。现在使用
FrameLayout
。我希望这有帮助