微信现在支持手势退出当前Activity了,我也接到需求就写了,代码已经整理好,效果图如下:
public GestureDetector gestureDetector = new GestureDetector( new OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { MyLogUtil.v("e1.getX()->", e1.getX() + ""); // 控制只右滑 if (e2.getX() - e1.getX() > 0 && (e1.getX() >= 0 && e1.getX() <= 100)) { if (Math.abs(e2.getX() - e1.getX()) > Math.abs(e2 .getY() - e1.getY()) && Math.abs(velocityX) > 1000) { overridePendingTransition(R.anim.open_next, R.anim.close_main); // finish(); onBackPressed(); } } return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); @Override public boolean dispatchTouchEvent(MotionEvent ev) { gestureDetector.onTouchEvent(ev); // scroll.onTouchEvent(ev); return super.dispatchTouchEvent(ev); }
本文出自 “梁肖技术中心” 博客,请务必保留此出处http://liangxiao.blog.51cto.com/3626612/1671773