DrawerLayout prevents call of MainActivity.onTouchEvent()

前端 未结 3 1226
梦谈多话
梦谈多话 2021-01-06 04:48

I have an app that overrides the onTouchEvent(MotionEvent ev) of the MainActivity to determine Two-Finger-Swipe and Pich-Open

相关标签:
3条回答
  • 2021-01-06 05:11

    A bit of a late update, but after having this issue for a couple of days, the solution that worked best for me was creating a CustomDrawerLayout. Then, casting the Context from the constructor as an Activity, called the Activity onTouchEvent from onInterceptTouchEvent.

    @Override public boolean onInterceptTouchEvent( MotionEvent ev )
    {
        getActivity().onTouchEvent( ev );
        return super.onInterceptTouchEvent( ev );
    }
    

    I find the code to be a lame hack... but works for me. Good luck!

    0 讨论(0)
  • 2021-01-06 05:13

    In case you or anyone else still need it, here is my implementation.
    Works perfectly with the exception of the "edge" not being taken from android code but as a constant (which I set).

    Please view this link:
    Android Navigation Drawer Doesn't Pass onTouchEvent to Activity

    0 讨论(0)
  • 2021-01-06 05:33

    I was having some issues recognizing gestures for items within the navigation drawer itself and came across requestDisallowInterceptTouchEvent. What I found was that I was getting the MotionEvent.ACTION_DOWN, but nothing after that because the NavigationDrawer was intercepting the touches. The key would be to call requestDisallowInterceptTouchEvent(true) on the down event in your touch handler in the activity so that you can handle the touch without it being intercepted.

    This presentation was also extremely useful when trying to figure out the touch system in Android.

    0 讨论(0)
提交回复
热议问题