Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set these two different images using position in android?

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:

enter image description here

Image One

enter image description here

Image Two

enter image description here

like image 859
start android Avatar asked Dec 06 '25 03:12

start android


1 Answers

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.

like image 155
Emil Adz Avatar answered Dec 08 '25 22:12

Emil Adz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!