Android 下拉重新整理 左右滑動 事件衝突
阿新 • • 發佈:2019-02-03
截獲listview和refreshlayout的dispatchTouchEvent方法,針對不同滑動通知父容器是否通知子控制元件獲取事件
CusMaterialRefreshLayout
float xDown = -1,yDown=-1; @Override public boolean dispatchTouchEvent(MotionEvent ev) { switch (ev.getAction()) { case MotionEvent.ACTION_DOWN: xDown = ev.getX(); yDown = ev.getY(); getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_MOVE: if(Math.abs(ev.getX()-xDown)<Math.abs(ev.getY()-yDown)) { getParent().requestDisallowInterceptTouchEvent(true); }else { getParent().requestDisallowInterceptTouchEvent(false); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: getParent().requestDisallowInterceptTouchEvent(false); break; } return super.dispatchTouchEvent(ev); }