繁体   English   中英

如何在相对布局中部分重叠视图

[英]How to partially overlap views within a relative layout

我正在尝试将粉红色按钮重叠在绿色视图上,但是我的“ z-offset”与我想要的相反。

我要寻找的效果只能通过框架布局实现吗?

在此处输入图片说明

<include layout="@layout/button"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_above="@+id/view"
    android:layout_alignParentRight="true"
    android:layout_marginRight="15dp"
    android:layout_marginBottom="-50dp"/>

<include layout="@layout/view"
    android:id="@id/view"
    android:layout_height="100dp"
    android:layout_width="match_parent"
    android:layout_alignParentBottom="true"/>

View s是按照在布局中列出的顺序绘制的,列出的第一个View在z轴上最远,最后一个是最靠近z轴。 如果要将按钮放在顶部,请在布局中最后列出该按钮。

<include layout="@layout/view"
    android:id="@id/view"
    android:layout_height="100dp"
    android:layout_width="match_parent"
    android:layout_alignParentBottom="true"/>

<include layout="@layout/button"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_above="@+id/view"
    android:layout_alignParentRight="true"
    android:layout_marginRight="15dp"
    android:layout_marginBottom="-50dp"/>

在相对布局中,最后添加的视图始终位于另一个视图之上,因此您只需要交换视图即可

首先@layout/view然后@layout/button

<include layout="@layout/view"
    android:id="@id/view"
    android:layout_height="100dp"
    android:layout_width="match_parent"
    android:layout_alignParentBottom="true"/>

<include layout="@layout/button"
    android:layout_height="wrap_content"
    android:layout_width="wrap_content"
    android:layout_above="@+id/view"
    android:layout_alignParentRight="true"
    android:layout_marginRight="15dp"
    android:layout_marginBottom="-50dp"/>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM