0

In the Android docs it says that the OnInterceptTouchEvent method of ViewGroup:

allows you to watch events as they are dispatched to your children

This somewhat implies to me, that it would only watch events from its children excluding its own events. Should that not be the case?

I did a quick test and the method fires regardless whether I tap on the child view (green square) or outside of it on the ViewGroup itself:

Custom view:

public class TestViewGroup extends FrameLayout {

    /* Constructors 
       and other bla bla... */

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Log.d("TestViewGroup", "TheTruth: " + ev.toString());
        return true;
    }
}

Layout:

<?xml version="1.0" encoding="utf-8"?>
<com.example.someapp.main.TestViewGroup xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <View
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:layout_gravity="bottom"
        android:background="#151" />
</com.example.someapp.main.TestViewGroup>

enter image description here

Why?

Eventually I will display a map in the place of the green square, and I would like to listen to only those touch screen events which start from outside of the map's area.

Crocodile
  • 5,724
  • 11
  • 41
  • 67
  • 1
    the first sentence in the docs is: `"Implement this method to intercept all touch screen motion events. "`, more [here](https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/java/android/view/ViewGroup.java#2511) – pskink Jan 24 '18 at 12:42
  • I want the green area to take touch events, but ignore them if they started (ACTION_DOWN) from outside off it. i.e.: when the user does a swipe down notion from the top of the screen outside of the green area. – Crocodile Jan 24 '18 at 13:49

0 Answers0