安卓:在布局之间的重叠放置的ImageView布局、ImageView

2023-09-06 06:07:37 作者:閨女稍息立正跟爹混i

我想将的ImageView 上的重叠点两种布局之间。在下面的图片中,我的目标是将放置的ImageView 其中白色广场。 注意:重叠点不一定会垂直居中,如下所示

I am trying to place an ImageView on the overlap point between two layouts. In the picture below, my goal would be to place the ImageView where the white square is. NOTE: The overlap point will not necessarily be centered vertically as shown below

这是可能的XML?

我只猜对了,现在就是要做到这一点,在实际的code本身。

My only guess right now is to do this in the actual code itself.

推荐答案

这将做你想做的,有固定高度,或编程计算无论是图片。

This will do what you want, with either an image of fixed height, or calculated programatically.

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