Created
December 15, 2015 15:26
-
-
Save pfn/4c235ace9cd38937c92a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public boolean onNestedFling(final CoordinatorLayout coordinatorLayout, final AppBarLayout child, View target, float velocityX, final float velocityY, boolean consumed) { | |
if (target instanceof RecyclerView && velocityY < 0) { | |
final RecyclerView recyclerView = (RecyclerView) target; | |
final long start = System.currentTimeMillis(); | |
recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { | |
@Override | |
public void onScrollStateChanged(RecyclerView recyclerView, int newState) { | |
if (newState == RecyclerView.SCROLL_STATE_IDLE) { | |
recyclerView.removeOnScrollListener(this); | |
final View firstChild = recyclerView.getChildAt(0); | |
final int childAdapterPosition = recyclerView.getChildAdapterPosition(firstChild); | |
final long end = System.currentTimeMillis(); | |
long dT = end - start; | |
if (childAdapterPosition == 0) | |
fling(coordinatorLayout, child, -child.getTotalScrollRange(), 0, Cv(dT) * Math.abs(velocityY)); | |
} | |
} | |
}); | |
} | |
return super.onNestedFling(coordinatorLayout, child, target, velocityX, velocityY, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment