Search code examples
androidtouchviewoverlappingtouch-event

Android make two overlapping views receive and handle the same touch event


I'm using a RelativeLayout to overlap two different views. Both Views fill the entire Screen. If the user touches the screen, I want both views to receive the TouchEvent and to excecute their own onTouch-Methods. At the moment, only one view receives the TouchEvent How can I make both views receive the TouchEvent?

Thank you in advance for your help.

EDIT: Here's the code

touchView.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                view1.onTouchEvent(event);
                view2.onTouchEvent(event);
                return false;
            }

        }); 

Solution

  • You can create a third invisible View and place it on top of the overlapping part. Then in its TouchEvent perform the actions of those two TouchEvents