android - overlap a button over another

android, android-relativelayout, button, overlap

Solution

You could do it by setting the margin to a negative value.

<?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView android:id="@+id/btn1"
                android:layout_width="100dp"
                android:layout_height="50dp"/>
            <ImageView android:layout_width="100dp"
                android:layout_height="50dp"
                android:layout_toRightOf="@id/btn1"
                android:layout_marginLeft="-20dp"/>
        </RelativeLayout>

Problem

how can i overlap a `Button` over another inside `RelativeLayout` ? Example Thanks. Here is what i've tried. Thanks ``` <RelativeLayout android:id="@+id/category" android:layout_width="match_parent" android:layout_height="0dp" android:layout_gravity="center_vertical|center_horizontal|center" android:gravity="center" android:orientation="horizontal" > <ImageView android:id="@+id/btn1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignTop="@id/btn2" android:layout_centerHorizontal="true" android:layout_centerInParent="true" android:layout_centerVertical="true" android:src="@drawable/btn1" /> <ImageView android:id="@+id/btn2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/btn2" /> </RelativeLayout> ```

Original source