switch上下滑动禁止scrollview滑动
时间: 2023-07-18 18:19:45 浏览: 60
可以在`ScrollView`的`onTouch`中判断触摸事件是否在`Switch`内,如果是,则禁止`ScrollView`滑动,否则允许。可以参考以下代码:
```
switch.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
int action = event.getAction();
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
scrollView.requestDisallowInterceptTouchEvent(true);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
scrollView.requestDisallowInterceptTouchEvent(false);
break;
}
return false;
}
});
```
其中,`requestDisallowInterceptTouchEvent`方法可以防止父级`ScrollView`拦截子级`Switch`的触摸事件。