how to half overlap imageview on another imageview in android

Asad picture Asad · Jan 11, 2017 · Viewed 13.7k times · Source

enter image description here

how can I overlap images half on one another from layout XML file like this image.

Answer

N J picture N J · Jan 11, 2017

Simply you can use RealtiveLayout and negative margins

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_landing"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/screen_background">


    <ImageView
        android:background="@color/black"
        android:id="@+id/img_background"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher" />

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:layout_below="@+id/img_background"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="-40dp"<!-- negative margin to half of height -->
        android:src="@mipmap/ic_launcher" />

</RelativeLayout>