pallavi
pallavi

Reputation: 432

How to position image1 on right top of the image2 in android?

How can i achieve a layout with 2 images in android, one image overlaying another image at the top right?

an image overlapping another image at the top right

https://i.sstatic.net/2ltkk.jpg I tried using relative layout, but i could position the overlay image by giving layout margin, but if i do that i cant support all screen sizes with that design. and also i couldnt position the overlay image with respect to the underimage. i want to design my layout like the pic i have shared.

Upvotes: 0

Views: 315

Answers (2)

pallavi
pallavi

Reputation: 432

I could get this working from the below code,

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

    <RelativeLayout
        android:id="@+id/c1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" >

        <ImageButton
            android:id="@+id/addnewcustomer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:src="@drawable/ic_launcher" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/c1"
        android:layout_toRightOf="@id/c1" >
    </RelativeLayout>

    <ImageButton
        android:id="@+id/hover1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/c1"
        android:layout_alignLeft="@+id/c1"
        android:layout_marginBottom="23dp"
        android:layout_marginLeft="22dp"
        android:background="@null"
        android:src="@drawable/ic_launcher" />

</RelativeLayout>

Upvotes: 1

Related Questions