如何在两个布局之间放置按钮

jar*_*d90 2 android android-layout android-button

我试图在两个布局之间放置一个按钮.

此外,如果我可以提供帮助,当您开始处理不同的屏幕尺寸保证金时,我不希望这样做.(在此图中,我试图将绿色按钮放在两个布局之间)

期望的结果布局

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_height="fill_parent"
    android:layout_width="fill_parent"
    android:background="@color/busy_white">

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

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/profile_default_round"
            android:background="@drawable/ring_status_clock_in"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="John Doe"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Manager"/>

    </LinearLayout>

    <RelativeLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@color/translucent_black_90"
        android:padding="16dp">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="center"
            android:layout_alignParentLeft="true">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Today Total"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="08:32"/>

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:layout_alignParentRight="true">

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="Week Total"
                android:gravity="right"/>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="24:32"
                android:gravity="center"/>

        </LinearLayout>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="-40dp">

        </LinearLayout>

        </RelativeLayout>

    <include layout="@layout/dashboard_clock_in_button" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

g4t*_*4th 12

这种UI要求多个层重叠.
所以FrameLayout就是这里的英雄.

为了基本了解我们希望实现的目标,我们可以绘制屏幕草图并确定放置位置 在此输入图像描述
FL是FrameLayout的主要容器.
你需要制作一个固定高度的按钮.假设BL的高度为bl dp.
只需向LinearLayout LL提供长度为bl/2 dp 的MarginBottom . 其中LL是将包含轮廓图像和作品的容器.

布局文件将如下所示

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/white"
    android:orientation="vertical"
    tools:context=".MainActivity">

    <LinearLayout
        android:id="@+id/ConcernedPortionofScreen"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.4"
        android:orientation="vertical">

        <!-- Parent FrameLayout 'FL' -->
        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <!-- This is Layout 'LL'
                 This is where you will place your image & the nice bg
            -->
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="25dp"
                android:background="#b2ebf2" />

            <!-- BL = 50dp -->
            <Button
                android:layout_width="100dp"
                android:layout_height="50dp"
                android:layout_gravity="bottom|center_horizontal"
                android:background="#558b2f"
                android:text="@android:string/ok"
                android:textSize="18sp"
                android:textColor="@android:color/white" />
        </FrameLayout>
    </LinearLayout>

    <LinearLayout
        android:id="@+id/RestofScreen"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.6"
        android:orientation="vertical" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)


输出将如下所示

在此输入图像描述