mRoundButtin.setOnTouchListener(new View.OnTouchListener() {
@Nullable
private MotionEvent mMotionEvent;
@Override
public boolean onTouch(View v, MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_UP && mMotionEvent != null && mMotionEvent.getAction() == MotionEvent.ACTION_DOWN){//если это тап
if (isWithinCirlce(event.getX(), event.getY()))return false;//если касания находится в пределах круга, пропускаем его далее
else {
//касание находится за логическими пределами кнопки. Считаем куда он попал и вызываем `performClick()` нужного на view
return true;
}
}
mMotionEvent = event;
return false;
}
});
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="80dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<Button
android:id="@+id/top_left"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="top|start"
android:background="@drawable/rect_black_stroke_40dp" />
<Button
android:id="@+id/top_right"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="top|end"
android:background="@drawable/rect_black_stroke_40dp" />
<Button
android:id="@+id/bottom_left"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="bottom|start"
android:background="@drawable/rect_black_stroke_40dp" />
<Button
android:id="@+id/bottom_right"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="bottom|end"
android:background="@drawable/rect_black_stroke_40dp" />
<Button
android:id="@+id/center"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center"
android:background="@drawable/circle_black_stroke_40dp" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="40dp"
android:height="40dp" />
<stroke
android:width="1dp"
android:color="#000" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<size
android:width="40dp"
android:height="40dp" />
<stroke
android:width="1dp"
android:color="#000" />
</shape>