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

前端 未结 8 715
深忆病人
深忆病人 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 13:51

    I think the best approach is to add a touch event and set return value True

    As you can see here:

      someView.setOnTouchListener(object: View.OnTouchListener {
            override fun onTouch(v: View?, event: MotionEvent?): Boolean{
                return true
            }
    
        })
    

    returning True means that the top view is handling the touch and no need to hand over the touch event to other views related.

提交回复
热议问题