我的手势叠加问题出现双击问题。当我按下操作栏中的某个项目时,它也会导致手势过度,并点击侦听器触发。当我使用操作栏并按下更新或刷新或者我在那里时,我不希望单击关闭?
activty_main.xml
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.gesture.GestureOverlayView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/gestureOverlayView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/LinearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp"
android:layout_gravity="start">
<TextView
android:id="@+id/timerTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="5sp"
android:text="@string/startTime"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textSize="30sp" />
<TextView
android:id="@+id/hanziTextView"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:ems="10"
android:gravity="center"
android:textSize="50sp" />
<TextView
android:id="@+id/instructionTextView"
android:layout_width="574dp"
android:layout_height="wrap_content"
android:layout_weight="0.05"
android:textSize="40sp" />
</LinearLayout>
</android.gesture.GestureOverlayView>
<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="#666"
android:dividerHeight="1dp"
android:background="#333"
android:paddingLeft="15sp"
android:paddingRight="15sp"
/>
</android.support.v4.widget.DrawerLayout>
mainactivity.class 的OnCreate
detector=new GestureDetector(getBaseContext(), this);
gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gLibrary.load()) {
finish();
}
GestureOverlayView gOverlay =
(GestureOverlayView) findViewById(R.id.gestureOverlayView1);
gOverlay.addOnGesturePerformedListener(this);
gOverlay.setGestureStrokeType(GestureOverlayView.GESTURE_STROKE_TYPE_MULTIPLE);
gOverlay.setGestureColor(Color.TRANSPARENT);
gOverlay.setUncertainGestureColor(Color.TRANSPARENT);
各种侦听器,例如OnClickListener,OnLongClickListener,OnGesturePerformedListener,OnGestureListener
@Override
public boolean onDown(MotionEvent arg0) {
return true;
}
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
if (Math.abs(diffX) > SWIPE_THRESHOLD && Math.abs(velocityX) > SWIPE_VELOCITY_THRESHOLD) {
if (diffX > 0) {
onSwipeRight();
} else {
onSwipeLeft();
}
}
} else {
if (Math.abs(diffY) > SWIPE_THRESHOLD && Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom();
} else {
onSwipeTop();
}
}
}
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
public void onSwipeRight() {
Log.d(TAG, "right");
}
public void onSwipeLeft() {
//Alot of stuff
}
public void onSwipeTop() {
}
public void onSwipeBottom() {
//Toast.makeText(this, "Pause", Toast.LENGTH_SHORT).show();
}
@Override
public void onLongPress(MotionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public boolean dispatchTouchEvent(MotionEvent e)
{
detector.onTouchEvent(e);
return super.dispatchTouchEvent(e);
}
@Override
public boolean onScroll(MotionEvent arg0, MotionEvent arg1, float arg2,
float arg3) {
// TODO Auto-generated method stub
return false;
}
@Override
public void onShowPress(MotionEvent arg0) {
// TODO Auto-generated method stub
Log.i(LOGTAG, "testsing4");
//Toast.makeText(getApplicationContext(), "Show Press gesture", 100).show();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
Log.i(LOGTAG, "testsing3");
return detector.onTouchEvent(event);
}
@Override
public boolean onSingleTapUp(MotionEvent e) {
//stuff
return true;
}
public boolean onSingleTapConfirmed(MotionEvent e) {
//Toast.makeText(getApplicationContext(), "Single Tap Gesture", 100).show();
Log.i(LOGTAG, "testsing1");
return true;
}
public void onGesturePerformed(GestureOverlayView overlay, Gesture gesture) {
//stuff
}