简体   繁体   English

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

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

I'm trying overlap the pink button over the green view, but my "z-offset" is the opposite of what I want. 我正在尝试将粉红色按钮重叠在绿色视图上,但是我的“ z-offset”与我想要的相反。

Is the effect I'm looking for only achievable with frame layouts? 我要寻找的效果只能通过框架布局实现吗?

在此处输入图片说明

<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 are drawn in the order they're listed in your layout, with the first one listed being the farthest away on the z-axis, the last being the closest. View s是按照在布局中列出的顺序绘制的,列出的第一个View在z轴上最远,最后一个是最靠近z轴。 If you want the button on top, list it last in the layout. 如果要将按钮放在顶部,请在布局中最后列出该按钮。

<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"/>

In relative layout, the view you add last is always on top of the other.So you just have to swap your views 在相对布局中,最后添加的视图始终位于另一个视图之上,因此您只需要交换视图即可

First @layout/view then @layout/button 首先@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