1

Layout

<ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false">
    <ConstraintLayout
        android:layout_width="24dp"
        android:layout_height="24dp"
        android:translationX="5dp"
        android:translationY="5dp"
        app:layout_constraintBottom_toTopOf="parent"
        app:layout_constraintEnd_toStartOf="parent">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:background="@android:color/black"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintBottom_toBottomOf="parent" />
    </ConstraintLayout>
</ConstraintLayout>

Layout

I want to handle click event for imageView, so I set simple listener for clicking it.

imageView.setOnClickListener {
    Log.d("ClickEvent", "imageView Clicked")
}

I can only receive click event when I touch orange area. But I want to receive click event when I touch red area also.
Note that red is clipped area, orange is non-clipped area (red+orange = imageView area) and gray is ConstraintLayout.

Is there any way to receive click event even if user touch clipped area? (If possible, it can do through code or xml?)

SlaneR
  • 684
  • 5
  • 19

1 Answers1

-2

you must initialize first

imageView = findViewById(R.id.imageView);

then you can call click listener

imageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
//do something
            }
        });
  • kotlin supports view access through id you wrote in xml, and setOnClickListener do the same thing. – SlaneR Jul 04 '19 at 01:43