Android开发ListView与ScrollView焦点冲突

一:初始化你的ListView之后,设置setOnTouchListener
二:判断按下行为
if (motionEvent.getAction() == MotionEvent.ACTION_DOWN)
判断移动行为
else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE)
三:设置与你冲突的那个控件不能触摸
scrollView.requestDisallowInterceptTouchEvent(true);


我的代码
myListView.setOnTouchListener(new View.OnTouchListener() {
    @Override
    public boolean onTouch(View view, MotionEvent motionEvent) {
        if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) {
            myscrollView.requestDisallowInterceptTouchEvent(true);
        }else if(motionEvent.getAction() == MotionEvent.ACTION_MOVE){
            myscrollView.requestDisallowInterceptTouchEvent(true);
        }
        return false;
    }
});

猜你喜欢

转载自blog.csdn.net/u014264125/article/details/129990883