I have two different images and would like to set them using different views but overlap slightly to match the below images. I also want to be able to set a different OnClickListener for each of them. I know with iOS I can set the view positions using x and y values but I'm not sure how to do this in Android.
How can I go about doing this?
Desired result:

Image One

Image Two

Try set those two images as ImageView's and put them inside a FrameLayout. That way you can set them as you want, So they can overlap one another. That way you can set an clickable and onClick properties for both of them separately:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ImageView
android:id="@+id/iFirstImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@drawable/sort_image_1"
android:clickable="true"
android:onClick="setFirstImageClick"
android:src="@drawable/sort_image_1" />
<ImageView
android:id="@+id/iSecondImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@drawable/sort_image_2"
android:clickable="true"
android:onClick="setSecondImageClick"
android:src="@drawable/sort_image_2" />
And create methods setFirstImageClick and setSecondImageClick in your activity to decide what each image click should do.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With