Intercept click touch but not scroll in Android
I am browsing webpages and doc to intercept click event and allow super control of scrolling in android app.
For example: by default, when I view my view, another view moves with it. I can get the click event, but the moment I get onDown, it returns true; another view cannot scroll with it. I tried to return false on onScroll but didn't do it.
I have some code with a basic onTouchListener or GestureDetectorCompat that does the same thing.
WIth Gesture Detector:
mGestureDetector = new GestureDetectorCompat(mContext, new ClickListener());
mRootFrameLayout.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
});
class ClickListener extends GestureDetector.SimpleOnGestureListener {
@Override
public boolean onDown(MotionEvent e) {
Log.d(LOG_TAG, "onDown");
return true;
}
@Override
public void onShowPress(MotionEvent e) {
Log.d(LOG_TAG, "onShowPress");
}
@Override
public boolean onSingleTapUp(MotionEvent event) {
Log.d(LOG_TAG, "click");
return true;
}
@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
Log.d(LOG_TAG, "onScroll");
return false;
}
@Override
public void onLongPress(MotionEvent e) {
Log.d(LOG_TAG, "onLongPress");
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
Log.d(LOG_TAG, "onFling");
return false;
}
}
Is there a way to defer an event on a custom view using DispatchTouchEvent or something else?
+3
source to share
No one has answered this question yet
Check out similar questions: