Android:在布局之间重叠放置ImageView

Dai*_*run 11 android android-layout android-xml

我试图ImageView在两个布局之间的重叠点上放置一个.在下图中,我的目标是放置ImageView白色方块所在的位置. 注意:重叠点不一定垂直居中,如下所示

在此输入图像描述

这可能是XML吗?

我现在唯一的猜测是在实际的代码本身中这样做.

编辑2016年8月3日:作为参考,我认为ConstraintLayouts可能是这些类型问题的最佳解决方案http://tools.android.com/tech-docs/layout-editor

pau*_*aul 33

这可以做你想要的,使用固定高度的图像,或以编程方式计算.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
        android:id="@+id/layoutTop"
        android:layout_width="match_parent"
        android:layout_height="200dp" >
    </RelativeLayout>

    <RelativeLayout
        android:id="@+id/layoutBottom"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_alignParentBottom="true"
        android:layout_below="@id/layoutTop" >
    </RelativeLayout>

    <ImageView
        android:id="@+id/overlapImage"
        android:layout_width="wrap_content"
        android:layout_height="40dp"
        android:layout_above="@id/layoutBottom"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="-20dp" <!-- This should be always half the height, can also be calculated and added programtically -->
        android:adjustViewBounds="true"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)