Okay, so this is my situation. On the picture that you see here, you have an ImageView which is all green, except for a transparent circle with a black stroke around it. Behind it is a RelativeLayout which has an all yellow background. What needs to happen is, when I click on the circle, the onClickListener for the RelativeLayout should start, but when I click somewhere else on the picture, the onClickListener for the ImageView should start. Is this even possible? If it is, than what should I do?
Some extra clarification:
- When the circle is clicked, the onClickListener of the ImageView is started, instead of RelativeLayout.
- The circle is a part of the ImageView
- Adding an extra View over the circle can't be the answer, because I'm trying to avoid that
Java:
package com.nicksoft.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.imageView).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "IMG", Toast.LENGTH_SHORT).show();
}
});
findViewById(R.id.rl).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "BG", Toast.LENGTH_SHORT).show();
}
});
}
}
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/rl"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFF00"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="@drawable/ic_test" />
</RelativeLayout>