Skip to content

Instantly share code, notes, and snippets.

@TakuSemba
Last active August 5, 2017 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TakuSemba/83e5baeb4947afeca8fb3e5970b72975 to your computer and use it in GitHub Desktop.
Save TakuSemba/83e5baeb4947afeca8fb3e5970b72975 to your computer and use it in GitHub Desktop.
@Override
int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager, @NonNull View targetView) {
int[] out = new int[2];
if (layoutManager.canScrollHorizontally()) {
out[0] = getDistance(layoutManager, targetView, OrientationHelper.createHorizontalHelper(layoutManager));
} else {
out[0] = 0;
}
if (layoutManager.canScrollVertically()) {
out[1] = getDistance(layoutManager, targetView, OrientationHelper.createVerticalHelper(layoutManager));
} else {
out[1] = 0;
}
return out;
}
int getDistance(RecyclerView.LayoutManager layoutManager, View targetView, OrientationHelper helper) {
final int childStart = helper.getDecoratedStart(targetView);
final int containerStart = helper.getStartAfterPadding();
return childStart - containerStart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment