android - ListView滑动删除,左右滑动会导致上下跟着滑动,求解决办法
黄舟
黄舟 2017-04-17 17:00:15
0
2
757
黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(2)
巴扎黑

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

Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template