Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to half overlap imageview on another imageview in android

enter image description here

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

like image 536
Asad Avatar asked Jan 11 '17 10:01

Asad


2 Answers

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>
like image 58
N J Avatar answered Oct 13 '22 19:10

N J


The FrameLayout is more optimised to perform this function. I carries less overhead.

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


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

    <ImageView
        android:layout_width="160dp"
        android:layout_height="160dp"
        android:layout_below="@+id/img_background"
        android:layout_gravity="bottom|center_horizontal"
        android:src="@mipmap/ic_launcher"
        android:background="@color/cardview_dark_background"/>

</FrameLayout>
like image 42
kanduken Avatar answered Oct 13 '22 17:10

kanduken