is this possible to use recyclerview like verticalpager .
what I want is when a user scrolls always the first item offset from the top be zero. like when you scroll in viewpager. is this possible?
Asked
Active
Viewed 2.0k times
17

max
- 5,963
- 12
- 49
- 80
2 Answers
51
Since API level 25 there's a PagerSnapHelper
for that:
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(mRecyclerView);
See also this answer.

Jyoti JK
- 2,141
- 1
- 17
- 40

user3252261
- 769
- 6
- 6
-
6Now this class is the part of RecyclerView compat library. You can use it on devices below api 25 – Paweł Dedio Aug 16 '18 at 10:36
7
Yes, you can.
You can use a simple LinearLayoutManager:
recyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL));
and for RecyclerView.Adapter
View item use layout_height="match_parent"
to get View on full width of screen.
or just use this lib: RecyclerViewPager
Updated:
recyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() {
@Override
public void onScrollStateChanged(int newState) {
if(newState == RecyclerView.SCROLL_STATE_IDLE) {
// special handler to avoid displaying half elements
scrollToNext();
}
animate();
}
@Override
public void onScrolled(int dx, int dy) {
animate();
}
});

Michael Celey
- 12,645
- 6
- 57
- 62

Victor Ponomarenko
- 490
- 1
- 7
- 12
-
Hi victore thanks for your attention, but like i said i want a verrtical srolling and i use match_parent to fill all view but my problem is when users scroll, i want my items always be top "normally screen can be half from one item and half from another wich i dont want",and i cannot use viewpager for some resaons.thanks again. – max Jun 23 '16 at 16:56
-
@max ok, i understood. in this case i recommend you to implement custom `LayoutManager`. Useful article http://wiresareobsolete.com/2014/09/building-a-recyclerview-layoutmanager-part-1/ – Victor Ponomarenko Jun 24 '16 at 12:16
-