我试图在两个布局之间放置一个按钮。
此外,如果我可以帮助的话,我不想在做这件事时留有边距,当你开始处理不同的屏幕尺寸时,边距会崩溃。 (在这张图片中,我试图将绿色按钮放在两个布局之间)
<?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>
最佳答案
这种UI需要多层重叠。
所以 FrameLayout 是这里的主角。
为了对我们希望实现的目标有一个基本的了解,我们可以绘制屏幕草图并决定位置
FL 是将成为 FrameLayout 的主要容器。
你需要做一个固定高度的按钮。假设 BL 的高度为 bl dp。
只需提供一个长度为 bl/2 dp 的 MarginBottom 给 LinearLayout LL。
其中,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>
输出将如下所示
关于android - 我如何在两个布局之间放置一个按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23921153/