1mRecyclerView.setHasFixedSize(true);
2
3 // use a linear layout manager
4 mLayoutManager = new LinearLayoutManager(this, LinearLayoutManager.HORIZONTAL, false);
5 mRecyclerView.setLayoutManager(mLayoutManager);
6
7 // specify an adapter (see also next example)
8 mAdapter = new DemoSlidesAdapter(getApplicationContext());
9 mRecyclerView.setAdapter(mAdapter);
10
11 final SnapHelper snapHelper = new LinearSnapHelper();
12 snapHelper.attachToRecyclerView(mRecyclerView);
13
14 mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
15
16 @Override
17 public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
18 super.onScrollStateChanged(recyclerView, newState);
19 if(newState == RecyclerView.SCROLL_STATE_IDLE) {
20 View centerView = snapHelper.findSnapView(mLayoutManager);
21 int pos = mLayoutManager.getPosition(centerView);
22 Log.e("Snapped Item Position:",""+pos);
23 }
24 }
25 });
26