Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Placing ImageView on overlap between layouts

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

enter image description here

Is this possible in XML?

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

EDIT 8/3/2016: For reference, I think ConstraintLayouts may be the best future solution for these types of problems http://tools.android.com/tech-docs/layout-editor

like image 804
Daiwik Daarun Avatar asked Aug 04 '14 21:08

Daiwik Daarun


People also ask

What is Z index in Android?

Z-Index for Annotation Stacking Order on Android This means the annotations with a lower z-index will be obscured if the annotations are overlapping. A z-index of 0 means that the annotation is all the way at the back, while the highest z-index means that the annotation is at the front.


1 Answers

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>
like image 68
paul Avatar answered Oct 01 '22 00:10

paul