Last active
August 5, 2017 07:07
-
-
Save TakuSemba/83e5baeb4947afeca8fb3e5970b72975 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 | |
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