java - Why doesn't this GestureDetector work? -
java - Why doesn't this GestureDetector work? -
i want observe fling-gestures on relativelayout called belowcontainer, code looks this:
// create new gesturelistener gesturedetector.simpleongesturelistener gesturelistener = new gesturedetector.simpleongesturelistener() { @override public boolean onfling(motionevent e1, motionevent e2, float velocityx, float velocityy) { log.d("test", "velocityx=" + velocityx); homecoming true; } }; // setup new gesturedetector, attach custom gesturelistener final gesturedetector gesturedetector = new gesturedetector(this, gesturelistener); // attach gesturedetector belowcontainer ontouchlistener belowcontainer.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view view, motionevent event) { log.d("test", "clicked!"); if(gesturedetector.ontouchevent(event)) { log.d("test", "gesture detected"); homecoming true; } homecoming false; } });
my app registers belowcontainer ontouch fine, somehow fling gesture not detected (the log shows "clicked!" , nil else). how come?
are testing on device or in emulator?
i don't see problem in code. belowcontainer big plenty have plenty room create fling gesture? have views within may "intercepting" touch events?
i advice log other methods gesture listener may grab know if getting other gestures instead.
you can seek pass ontouchevents activity , not view... way easier grab gesture events (just create sure working!) (override activity.ontouchevent
, pass event gesture detector.
java android
Comments
Post a Comment