Question

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;
            }

        }); 
Was it helpful?

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

OTHER TIPS

For top view assign clickable=false

it will allow the touch to intercept through it

You could try to get to check if the rawX & rawY of the TouchEvent are within the hitRect of the view that didn't get the event. If it did, you can use dispatchTouchEvent(MotionEvent) to send the TouchEvent tot the view that didn't get the event

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top