Iβve been racking my brains googled from google for the last couple of hours, and not one of the examples in StackOverflow or other places worked for me, so here it is ...
I have a custom view that extends LinearLayout and implements GestureDetector.OnGestureListener .
In my custom layout, I have 3 buttons, each of which has a click listener. I want to be able to Fling throughout the view in order to accomplish something, but also to be able to click on buttons.
My onFling function works fine if I go inside, but not on one of the buttons. If I go through one of the buttons, in most cases it clicks or does nothing.
Here is the relevant part of my code:
@Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH) { return false; } // right to left swipe if (e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { viewFlipper.setInAnimation(slideLeftIn); viewFlipper.setOutAnimation(slideLeftOut); viewFlipper.showNext(); return true; } else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) { viewFlipper.setInAnimation(slideRightIn); viewFlipper.setOutAnimation(slideRightOut); viewFlipper.showPrevious(); return true; } return false; } @Override public boolean onDown(MotionEvent e) { // TODO Auto-generated method stub return true; } @Override public void onLongPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { // TODO Auto-generated method stub return false; } @Override public void onShowPress(MotionEvent e) { // TODO Auto-generated method stub } @Override public boolean onSingleTapUp(MotionEvent e) { // TODO Auto-generated method stub return false; } @Override public boolean onTouchEvent(MotionEvent event) { if (gestureDetector.onTouchEvent(event)) { return gestureDetector.onTouchEvent(event); } return false; }
tried any combination return true; return false; I would have thought ... I would have thanked for any help! :)
Thanks!
Lior luz
source share