gpt4 book ai didi

android - 如何对齐重叠两个布局的屏幕按钮中心

转载 作者:行者123 更新时间:2023-11-29 20:26:56 29 4
gpt4 key购买 nike

我需要一个包含 3 个部分的布局,如下所示

enter image description here

它包含 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" />

关于android - 如何对齐重叠两个布局的屏幕按钮中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32410502/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com