Home  >  Q&A  >  body text

android - ListView滑动删除,左右滑动会导致上下跟着滑动,求解决办法

黄舟黄舟2761 days ago745

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 17:02:15

    I haven’t looked at your code, but I have encountered the same problem. First, you need to judge the finger displacement to determine which component the current Touch event should be captured by, such as your current left and right sliding, your current component has your listview, and Have every item in your listview. Now that everything is understood, it will be easy to do. Post an example, otherwise it would be insincere.

    class YScrollDetector extends GestureDetector.SimpleOnGestureListener {
        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            
            if (Math.abs(distanceX) >= Math.abs(distanceY)) {
                //父亲不滑动
                setParentScrollAble(false);
                return true;
            }else{
                setParentScrollAble(true);
            }
            return false;
        }
    }

    This is used to judge left and right swiping and select to capture.

    private void setParentScrollAble(boolean flag) {
        if(parentListView!=null){
            parentListView.requestDisallowInterceptTouchEvent(!flag);
        }
    }

    This is used to distribute events

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 17:02:15

    If you haven’t solved it yet, you can try this open source example: https://github.com/timroes/EnhancedListView supports the sliding deletion you mentioned

    reply
    0
  • Cancelreply