GestureDetector-onfling不执行
今天在做计算器的时候,遇到了一个问题,就是当我使用GestureDetector的时候,onFling方法不执行,而其他的可以执行。代码如下
@Override public boolean onDown(MotionEvent arg0) { android.util.Log.e("zhangshuli", "getx(down)===="+arg0.getX()+"getY(down)===="+arg0.getY()); myGestureSign = false; return false; } @Override public boolean onFling(MotionEvent arg0, MotionEvent arg1, float arg2, float arg3) { /* Vanzo:zhangshuli on: Tue, 24 Mar 2015 20:52:05 +0000 * modify for v5 calculator if (myGestureSign) { return true; } if (Math.abs(arg0.getX() - arg1.getX()) > 120.0F) { myGestureSign = true; if (!mDrawerLayout.isDrawerVisible(GravityCompat.END)) { mDrawerLayout.openDrawer(GravityCompat.END); } } else if (arg1.getX() - arg0.getX() > 120.0F) { if (mDrawerLayout.isDrawerVisible(GravityCompat.END)) { mDrawerLayout.closeDrawer(GravityCompat.END); } } android.util.Log.e("zhangshuli", "arg0.getx(fling)===="+arg0.getX()+"getY(fling)===="+arg0.getY()+"arg1.getx(fling)===="+arg1.getX()+"arg1.getY(fling)===="+arg1.getY()); */ // End of Vanzo: zhangshuli return false; }
后来在网上找到了原因,只要把onDown()的返回值更改成true就行了
如下
@Override public boolean onDown(MotionEvent arg0) { android.util.Log.e("zhangshuli", "getx(down)===="+arg0.getX()+"getY(down)===="+arg0.getY()); myGestureSign = false; return true; }