I'm having a bit of an issue using NestedScrollView
. My use case uses 2 NestedScrollView
, a parent and a child. I have overridden the parent's onNestedPreScroll
method to sometimes consume scroll pixels before the child:
@Override
public void onNestedPreScroll(View target, int dx, int dy, int[] consumed) {
if (dy > 0 && getScrollY() < getScrollRange()) {
int oldScrollY = getScrollY();
scrollBy(0, dy);
consumed[1] = getScrollY() - oldScrollY;
}
}
I have also overridden the parent's onNestedPreFling
to consume fling before the child:
@Override
public boolean onNestedPreFling(View target, float velocityX, float velocityY) {
if (velocityY > 0 && getScrollY() < getScrollRange()) {
fling((int) velocityY);
return true;
}
return false;
}
However, I noticed that when the parent consumes the entirety of a scroll in onNestedPreScroll
, the parent's onNestedPreFling
is not being called.
From my investigation, it appears that if the parent consumes the entire scroll, the child reacts as if an ACTION_MOVE
event with deltaY=0
has occurred. This causes the absolute value deltaY
to be less than mTouchSlop
and mIsBeingDragged
would remain being set to false
. Since mTouchSlop
is false
, no fling calculation is made when an ACTION_UP
event occurs in the child.
Is there a different approach I could be using to get the fling velocity for the parent NestedScrollView
?
NestedScrollView
: https://developer.android.com/reference/android/support/v4/widget/NestedScrollView.html