max max - 5 months ago 688
Android Question

use RecyclerView like vertical viewpager

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?

Answer

Yes, you can.

You can use simple LinearLayoutManager:

recyclerView.setLayoutManager(new LinearLayoutManager(getContenxt(), 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();
    }
});