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?
ViewPager2 comes with right-to-left support, orientation changes, now you can use RecyclerView with ViewPager which can enable usage of DiffUtils, LayoutManager, PageTransformations, Fragments as pages which are modifiable etc.
To be able to scroll through a vertical list of items that is longer than the screen, you need to add a vertical scrollbar. Inside RecyclerView , add an android:scrollbars attribute set to vertical .
The RecyclerView needs an adapter to populate the views in each row (horizontal item) with your data.
Today, suddenly Recyclerview. Viewholder became deprecated. Other, android project is no deprecated.
Since API level 25 there's a PagerSnapHelper
for that:
SnapHelper snapHelper = new PagerSnapHelper();
snapHelper.attachToRecyclerView(mRecyclerView);
See also this answer.
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();
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With