解决ScrollView嵌套ListView滑动冲突
 重写listview:
    public class ListViewVi extends ListView {
     
     //重写构造
        public ListViewVi(Context context) {
            this(context, null);
        }
     
        public ListViewVi(Context context, AttributeSet attrs) {
            this(context, attrs, 0);
        }
     
        public ListViewVi(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
        }
     
        @Override
        public boolean onInterceptTouchEvent(MotionEvent ev) {
            return super.onInterceptTouchEvent(ev);
        }
     
     
        //为listview/Y,设置初始值,默认为0.0(ListView条目一位置)
        private float mLastY;
     
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
     
        //重点在这里
            int action = ev.getAction();
     
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                    super.onInterceptTouchEvent(ev);
                    //不允许上层viewGroup拦截事件.
                    getParent().requestDisallowInterceptTouchEvent(true);
                    break;
                case MotionEvent.ACTION_MOVE:
                    //满足listView滑动到顶部,如果继续下滑,那就让scrollView拦截事件
                    if (getFirstVisiblePosition() == 0 && (ev.getY() - mLastY) > 0) {
                        //允许上层viewGroup拦截事件
                        getParent().requestDisallowInterceptTouchEvent(false);
                    }
                    //满足listView滑动到底部,如果继续上滑,那就让scrollView拦截事件
                    else if (getLastVisiblePosition() == getCount() - 1 && (ev.getY() - mLastY) < 0) {
                        //允许上层viewGroup拦截事件
                        getParent().requestDisallowInterceptTouchEvent(false);
                    } else {
                        //不允许上层viewGroup拦截事件
                        getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    //不允许上层viewGroup拦截事件
                    getParent().requestDisallowInterceptTouchEvent(true);
                    break;
            }
     
            mLastY = ev.getY();
            return super.dispatchTouchEvent(ev);
     
        }
     
        @Override
        public boolean onTouchEvent(MotionEvent ev) {
            return super.onTouchEvent(ev);
        }
    }
之后再布局中引用重写后的listview,  即可解决滑动冲突
     <group.bw.com.tachevent.ListViewVi
                    android:id="@+id/list_view"
                    android:layout_width="match_parent"
                    android:layout_height="400dp">
     
                </group.bw.com.tachevent.ListViewVi>
 
--------------------- 
作者:币圈小韭菜 
来源:CSDN 
原文:https://blog.csdn.net/liu_qunfeng/article/details/84644309 
版权声明:本文为博主原创文章,转载请附上博文链接!
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号