Why do ViewGroup
's only get ACTION_DOWN
in the onInterceptTouchEvent
? According to the docs, as long as false is returned it should receive all the event types. http://developer.android.com/reference/android/view/ViewGroup.html#onInterceptTouchEvent%28android.view.MotionEvent%29 Point #3.
Sample code:
public class MainActivity extends Activity { private static final String TAG = MainActivity.class.getSimpleName(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new Container(this)); } private class Container extends LinearLayout { public Container(Context context) { super(context); setBackgroundColor(0xFF0000FF); } @Override public boolean onInterceptTouchEvent(MotionEvent ev) { Log.i(TAG, "onInterceptTouchEvent"); int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: Log.i(TAG, "onInterceptTouchEvent.ACTION_DOWN"); break; case MotionEvent.ACTION_MOVE: Log.i(TAG, "onInterceptTouchEvent.ACTION_MOVE"); break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: Log.i(TAG, "onInterceptTouchEvent.ACTION_UP"); break; } return super.onInterceptTouchEvent(ev); } } }
I'll answer my own question: onInterceptTouchEvent only get called if the parent has a child view which returns "true" from onTouchEvent. Once the child returns true, the parent now has a chance to intercept that event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With