Skip to content

Instantly share code, notes, and snippets.

@brendanw
Created February 3, 2017 01:43
Show Gist options
  • Save brendanw/be5e22bc2f9d54836e9ab309cd69c487 to your computer and use it in GitHub Desktop.
Save brendanw/be5e22bc2f9d54836e9ab309cd69c487 to your computer and use it in GitHub Desktop.
/**
* Need to return true here to continue hearing updates from the child
* for the duration of the scroll
*/
public boolean onStartNestedScroll(View child, View target, int nestedScrollAxes) {
return true;
}
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
int [] pos = new int[2];
target.getLocationOnScreen(pos);
if (pos[1] <= 0 && dy > 0) {
Log.d(TAG, "onNestedPreScroll: child consumes");
//allow the child to consume the event
} else if (pos[1] <= 0 && target.getScrollY() > 0) {
Log.d(TAG, "onNestedPreScroll: child consumes");
//allow the child to consume the event
} else {
Log.d(TAG, "onNestedPreScroll: parent consumes");
//we consume the event
scrollBy(0, dy);
consumed[1] = dy;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment