use of me.relex.recyclerpager.SnapPageScrollListener in project CircleIndicator by ongakuer.
the class LoopRecyclerViewFragment method onViewCreated.
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
mAdapter = new LoopRecyclerAdapter(5);
mIndicator = view.findViewById(R.id.indicator);
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
LinearLayoutManager layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setAdapter(mAdapter);
mIndicator.createIndicators(mAdapter.getRealItemCount(), 0);
PagerSnapHelper pagerSnapHelper = new PagerSnapHelper();
pagerSnapHelper.attachToRecyclerView(recyclerView);
recyclerView.addOnScrollListener(new SnapPageScrollListener() {
@Override
public void onPageSelected(int position) {
mIndicator.animatePageSelected(mAdapter.getRealPosition(position));
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
if (positionOffsetPixels == 0) {
recyclerView.scrollToPosition(mAdapter.getLoopPosition(position));
}
}
});
}
Aggregations