Touch a button behind an invisible view

前端 未结 3 807
执念已碎
执念已碎 2021-01-07 08:03

\"enter

See the picture, i have a button and it is behind an invisible view (the red l

3条回答
  •  情歌与酒
    2021-01-07 08:51

    1 way you can do this is: 1. add an onTouch(View view, MotionEventevent) Listener to your layout 2. get the buttons bounds 3. Check if the touch event was done inside the bounds

    The code should look something like this:

    Button button;
    Rect rect;
    
    onCreate(){
    rect = button.getClipBounds();
    layout.setOnTouchListener(this)
    }
    
    onTouch(View view, MotionEvent event){
        if(rect.contains(event.getX(), event.getY())
            //insert action here
    }
    

提交回复
热议问题