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

时间:2015-11-16 13:01:56

标签: android

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

我正在寻找的效果是否只能通过帧布局实现?

enter image description here

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

2 个答案:

答案 0 :(得分:0)

View按照它们在您的布局中列出的顺序绘制,第一个列出的是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"/>

答案 1 :(得分:0)

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

首先@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"/>