Last active
April 24, 2019 23:36
-
-
Save bashizip/a360ac9ec33158cae5a6709a06dd0a36 to your computer and use it in GitHub Desktop.
CirleLinearAdapter
This file contains hidden or 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
public class CircleLayoutManager extends TurnLayoutManager { | |
public CircleLayoutManager(Context context, int gravity, int orientation, int radius, int peekDistance, boolean rotate) { | |
super(context, gravity, orientation, radius, peekDistance, rotate); | |
} | |
public CircleLayoutManager(Context context, int radius, int peekDistance) { | |
super(context, radius, peekDistance); | |
} | |
@Override | |
public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) { | |
RecyclerView.SmoothScroller smoothScroller = new CenterSmoothScroller(recyclerView.getContext()); | |
smoothScroller.setTargetPosition(position); | |
startSmoothScroll(smoothScroller); | |
} | |
private static class CenterSmoothScroller extends LinearSmoothScroller { | |
CenterSmoothScroller(Context context) { | |
super(context); | |
} | |
@Override | |
public int calculateDtToFit(int viewStart, int viewEnd, int boxStart, int boxEnd, int snapPreference) { | |
return (boxStart + (boxEnd - boxStart) / 2) - (viewStart + (viewEnd - viewStart) / 2); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment