Android ScrollView和ListView滑动冲突解决记录

  private int mLastX;
    private int mLastY;
    public View.OnTouchListener onTouchListener = new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent ev) {
            Log.e("InvParent", "--------v.getParent().getParent().getParent().getParent()--------->" + view.getParent().getParent().getParent().getParent());
            Log.e("InvParent", "--------v.getParent().getParent().getParent()--------->" + view.getParent().getParent().getParent());
            Log.e("InvParent", "--------v.getParent().getParent()--------->" + view.getParent().getParent());
            Log.e("InvParent", "--------v.getParent()--------->" + view.getParent());
            int x = (int) ev.getX();
            int y = (int) ev.getY();
            switch (ev.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    view.getParent().requestDisallowInterceptTouchEvent(true);

                    break;
                case MotionEvent.ACTION_MOVE:

                    int xDiff = Math.abs(x - mLastX);
                    int yDiff = Math.abs(y - mLastY);

                    if (xDiff < yDiff) {
                        view.getParent().requestDisallowInterceptTouchEvent(false);
                    } else {
                        view.getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    break;
            }
            mLastX = x;
            mLastY = y;
//                return super(ev);
            return false;
        }
    };

 

posted @ 2018-10-23 13:24  丁先森  阅读(1328)  评论(0编辑  收藏  举报