my working solution to this problem is using an invisible layer above the view with children as following:
<RelativeLayout
android:id="@+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout"
android:layout_alignStart="@+id/linearLayout"
android:layout_alignParentTop="true">
...
</RelativeLayout>
<View
android:id="@+id/gesture_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout"
android:layout_alignStart="@+id/linearLayout"
android:layout_alignParentTop="true"
android:focusable="true"
android:focusableInTouchMode="true" />
where contentLayout
contains multiple children including some buttons.
Second step is catching touch events on this gesture_view
and proxying them to both contentLayout
and my GestureDetector code (similar to the one you linked on the question) as following:
gesture_view.setOnTouchListener { _, event ->
contentLayout.dispatchTouchEvent(event)
gestureListener.onTouch(event)
true
}
Note, you need to be careful about how you deliver the events to the view behind gesture_view
. Simply contentLayout#onTouch
will not work. It has to be contentLayout.dispatchTouchEvent