Layout
!* Container is a relative layout contains two custom views: OuterView1 and InnerView2 * Outer View1 is a custom view, matching the parent’s size (full screen) * Inner View2 is also a custom view, laid on top of OuterView1 overlapping it.
- Container is a relative layout contains two custom views: OuterView1 and InnerView2
- Outer View1 is a custom view, matching the parent’s size (full screen)
- Inner View2 is also a custom view, laid on top of OuterView1 overlapping it.
On both OuterView1 and InnerView2, I want to capture these touch events onSingleTapConfirmed() and onFling(). The area where both OuterView1 and InnerView2 are overlapping, I want the control to be passed to touch event methods of both views.
I tried this:
Container class
@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
outerView1.onTouchEvent(ev);
innerView2.onTouchEvent(ev);
return false;
}
OuterView1 class
@Override
public boolean onTouchEvent(MotionEvent event) {
gesture.onTouchEvent(event);
return true;
}
gesture is an instance of GestureDetector.SimpleOnGestureListener with log statements for onDown(), onFling() and onSingleTapConfirmed() methods
InnerView2 class
@Override
public boolean onTouchEvent(MotionEvent event) {
gesture.onTouchEvent(event);
return true;
}
gesture is an instance of GestureDetector.SimpleOnGestureListener with log statements for onDown(), onFling() and onSingleTapConfirmed() methods
With this approach, I consistently get callback in onDown() methods of both views. But I don’t see a consistent behaviour on onSingleTapConfirmed() and onFling() methods
When I tapped in the red circle (in the screenshot) three times and I got three different behaviour
First try (desired behaviour)
10-14 09:03:14.155: I/OuterView1(27776): OuterView1.onDown() 10-14 09:03:14.155: I/InnerView2(27776): InnerView2.onDown() 10-14 09:03:14.155: W/GestureDetector(27776): [pen gesture] isConsideredDoubleTap - timeout 10-14 09:03:14.155: I/InnerView2(27776): InnerView2.onDown() 10-14 09:03:14.460: I/OuterView1(27776): OuterView1.onSingleTapConfirmed() 10-14 09:03:14.460: I/InnerView2(27776): InnerView2.onSingleTapConfirmed()
Second try (Only one view gets onSingleTapConfirmed())
10-14 09:04:11.615: I/OuterView1(27776): OuterView1.onDown() 10-14 09:04:11.615: I/InnerView2(27776): InnerView2.onDown() 10-14 09:04:11.615: W/GestureDetector(27776): [pen gesture] isConsideredDoubleTap - timeout 10-14 09:04:11.615: I/InnerView2(27776): InnerView2.onDown() 10-14 09:04:11.915: I/OuterView1(27776): OuterView1.onSingleTapConfirmed()
Third try (One view gets onFling() and another gets onSingleTapConfirmed())
10-14 09:04:04.180: I/OuterView1(27776): OuterView1.onDown() 10-14 09:04:04.180: I/InnerView2(27776): InnerView2.onDown() 10-14 09:04:04.180: W/GestureDetector(27776): [pen gesture] isConsideredDoubleTap - timeout 10-14 09:04:04.180: I/InnerView2(27776): InnerView2.onDown() 10-14 09:04:04.255: I/InnerView2(27776): InnerView2.onFling() 10-14 09:04:04.480: I/OuterView1(27776): OuterView1.onSingleTapConfirmed()
Could you help me capture touch events on both OuterView1 and InnerView2?