Java 在Android应用程序中使用抽屉布局时手势不起作用
我有一个Android应用程序,只有一个活动。此活动使用此布局:Java 在Android应用程序中使用抽屉布局时手势不起作用,java,android,gesture-recognition,drawerlayout,Java,Android,Gesture Recognition,Drawerlayout,我有一个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_pa
<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>
我以这种方式覆盖了onTouchEvent:
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1) {
this.mScaleDetector.onTouchEvent(event);
} else {
this.mDetector.onTouchEvent(event);
}
return super.onTouchEvent(event);
}
我的问题是没有检测到手势(尽管我可以用刷卡手势打开抽屉)。例如,如果我用线性布局替换抽屉布局,则不会出现此问题,因此原因是导航抽屉。我做错了什么?您必须为抽屉布局设置TouchListener。 乙二醇/
你找到这个问题的解决方案了吗?我没有时间测试@vivoila解决方案,但我会在下周测试。我告诉你一件事。我有一个类似的问题:。在我更新我的问题之前,我测试了@vivoila解决方案,但这对我不起作用。你得到答案了吗?
@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getPointerCount() > 1) {
this.mScaleDetector.onTouchEvent(event);
} else {
this.mDetector.onTouchEvent(event);
}
return super.onTouchEvent(event);
}
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;
}
});