如何对齐重叠两个布局的屏幕按钮中心
How to align button center of screen overlapping two layouts
我需要一个包含 3 个部分的布局,如下所示
它包含 3 个部分的页眉、正文和页脚以及一个按钮。我需要这个按钮恰好位于屏幕中心,重叠页脚和正文。
现在我正在设置固定的 dp 边距来实现这一点。但它在不同的屏幕上没有正确对齐。我该如何设置这个设计?我需要这个按钮恰好位于屏幕的中央。下面是我的布局xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<RelativeLayout
android:background="@color/transparent_black"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="100dp"
/>
<RelativeLayout
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/header"
android:layout_above="@+id/relativeLayout2" />
<RelativeLayout
android:background="@color/transparent_black"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/relativeLayout2"></RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/ic_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="@id/body"
android:layout_marginBottom="-32dp"
android:layout_marginRight="160dp" />
</RelativeLayout>
试试这个
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/ic_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@id/body"
android:layout_marginBottom="-32dp" />
我需要一个包含 3 个部分的布局,如下所示
它包含 3 个部分的页眉、正文和页脚以及一个按钮。我需要这个按钮恰好位于屏幕中心,重叠页脚和正文。 现在我正在设置固定的 dp 边距来实现这一点。但它在不同的屏幕上没有正确对齐。我该如何设置这个设计?我需要这个按钮恰好位于屏幕的中央。下面是我的布局xml代码
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center_horizontal">
<RelativeLayout
android:background="@color/transparent_black"
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="100dp"
/>
<RelativeLayout
android:id="@+id/body"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/header"
android:layout_above="@+id/relativeLayout2" />
<RelativeLayout
android:background="@color/transparent_black"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="@+id/relativeLayout2"></RelativeLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/ic_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignBottom="@id/body"
android:layout_marginBottom="-32dp"
android:layout_marginRight="160dp" />
</RelativeLayout>
试试这个
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:src="@drawable/ic_plus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignBottom="@id/body"
android:layout_marginBottom="-32dp" />