2013-07-26 15 views
9

Mam aplikację na Androida z jedną aktywnością. Działalność ta wykorzystuje ten układ:Gesty nie działają podczas używania DrawerLayout w aplikacji Android

<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> 

Następnie, w moim źródle Mam dwa detektory gest zdefiniowane w konstruktorze:

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

A ja unieważniając onTouchEvent ten sposób:

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

Moim problemem jest to, że gesty nie są wykrywane (chociaż mogę otworzyć szufladę gestem machnięcia). Ten problem nie występuje, jeśli zastępuję układ kreacji za pomocą, na przykład, układu liniowego, więc przyczyną jest szuflada nawigacji. Co ja robię źle?

+0

Czy otrzymałeś rozwiązanie tego problemu? – owe

+0

Nie miałem czasu, aby przetestować rozwiązanie @vivoila, ale zrobię to w przyszłym tygodniu. Powiem ci coś. –

+0

Mam podobny problem: http://stackoverflow.com/questions/21040150/drawerlayout-prevents-call-of-mainactivity-ontouchevent#comment31631959_21040150. Zanim wprowadziłem aktualizacje w moim pytaniu, testowałem rozwiązanie @vivoila, ale to nie działało dla mnie. – owe

Odpowiedz

1

należy ustawić TouchListener dla układu szuflady. 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; 
     } 
    }); 
Powiązane problemy