android - How to capture onTouch events on two overlapping views? -
android - How to capture onTouch events on two overlapping views? -
layout
container relative layout contains 2 custom views: outerview1 , innerview2 outer view1 custom view, matching parent’s size (full screen) inner view2 custom view, laid on top of outerview1 overlapping it.on both outerview1 , innerview2, want capture these touch events onsingletapconfirmed() , onfling(). area both outerview1 , innerview2 overlapping, want command passed touch event methods of both views.
i tried this:
container class
@override public boolean onintercepttouchevent(motionevent ev) { outerview1.ontouchevent(ev); innerview2.ontouchevent(ev); homecoming false; }
outerview1 class
@override public boolean ontouchevent(motionevent event) { gesture.ontouchevent(event); homecoming true; }
gesture instance of gesturedetector.simpleongesturelistener log statements ondown(), onfling() , onsingletapconfirmed() methods
innerview2 class
@override public boolean ontouchevent(motionevent event) { gesture.ontouchevent(event); homecoming true; }
gesture instance of gesturedetector.simpleongesturelistener log statements ondown(), onfling() , onsingletapconfirmed() methods
with approach, consistently callback in ondown() methods of both views. don’t see consistent behaviour on onsingletapconfirmed() , onfling() methods
when tapped in reddish circle (in screenshot) 3 times , got 3 different behaviour
first seek (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 seek (only 1 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 seek (one view gets onfling() , 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 help me capture touch events on both outerview1 , innerview2?
so in case of overlapping views - touch events dispatched topmost kid 1 behind, 1 behind 2nd kid , on. however, if topmost kid consume touch event (i.e. handle upon receiving it) views underneath view not receive touch events.
if ontouchevent returns 'true' telling view manager has handled touch , not want event dispatched other views. if want view underneath view receive touch want homecoming 'false' ontouchevent first view, in case innerview.
also, in code noticed programmatically dispatching touch events 2 views container class. causes innerview receive touch when outerview clicked. if want functionality ok. if want innerview events when touched dont want container class phone call ontouchevent explicitly on 2 views. view hierarchy you.
about receiving onfling or onsingletapconfirmed on both views - (assuming want allow touch events go through views behind well, homecoming 'false' ontouchevent innerview) innerview has passed event view behind it, doesnt end of gesture realize fling occured , onsingletapconfirmed. if want still may have dispatch touch events programmatically @ end of gesture detected outerview. meaning, if outerview got fling gesture fling innerview , programmatically create gesture happen innerview well. quite complicated , dispatching touches backwards in hierarchy not usual thing.
hopefully havent confused on this. sense free inquire if haven't been clear , seek again.
this helpful: handling touchevents in viewgroup
android overlapping touch-event
Comments
Post a Comment