Android: How to prevent any touch events from being passed from a view to the one underneath it?

前端 未结 8 714
深忆病人
深忆病人 2021-01-31 13:38

Specifically using the code below, is there a way to modify it so that the activity under this newly created view does not receive any gestures?

View v1 = new Vi         


        
8条回答
  •  遥遥无期
    2021-01-31 14:05

    You can do this too. You can set touch listener to child view and then in onTouch() event, you can block intercept touch event of parent.

    i.e.

    View v = findViewById(R.id.sample_view);
    v.setOnTouchListener(new OnTouchListener() {
        // Setting on Touch Listener for handling the touch inside ScrollView
        @Override
        public boolean onTouch(View v, MotionEvent event) {
        // Disallow the touch request for parent scroll on touch of child view
        v.getParent().requestDisallowInterceptTouchEvent(true);
        return false;
        }
    });
    

提交回复
热议问题