10

I have an Android app with a single Activity. This activity uses this layout:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>

Then, in my source I have two gesture detectors defined in the constructor:

mDetector = new GestureDetectorCompat(this, new CustomGestureListener());
mScaleDetector = new ScaleGestureDetector(this, new CustomScaleGestureListener());

And I'm overriding onTouchEvent this way:

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (event.getPointerCount() > 1) {
        this.mScaleDetector.onTouchEvent(event);
    } else {
        this.mDetector.onTouchEvent(event);
    }
    return super.onTouchEvent(event);
}

My problem is that gestures are not detected (although I can open the drawer with a swipe gesture). This problem doesn't occur if I replace the drawerlayout with, for example, a linear layout, so the cause is the navigation drawer. What am I doing wrong?

David Moreno García
  • 4,423
  • 8
  • 49
  • 82
  • Did you get a solution for this problem? – owe Jan 09 '14 at 15:03
  • I hadn't the time to test @vivoila solution but I'll do it next week. I'll tell you something. – David Moreno García Jan 10 '14 at 14:39
  • I got a similar problem: http://stackoverflow.com/questions/21040150/drawerlayout-prevents-call-of-mainactivity-ontouchevent#comment31631959_21040150. Before I made the updates in my question I tested @vivoila solution but this didn't work for me. – owe Jan 10 '14 at 14:47
  • Did you get the answer? – Erika Mar 05 '18 at 13:09

1 Answers1

3

you have to set a TouchListener for your drawer layout. eg/

gestureDetector = new GestureDetector(this, new CustomGestureListener());

    mDrawerLayout.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (gestureDetector.onTouchEvent(event)) {
                return true;
            }
            return false;
        }
    });
vivoila
  • 31
  • 2