Visit GitHub RepoView Pagers

Infinite View Pager

Augment Android's ViewPager with wrap-around functionality. Original StackOverflow question:


With a normal ViewPager, you can only scroll from the first page to second page (and so forth), from left-to-right. Once you reach the last page, your only option is to scroll backwards, right-to-left. In other words, 'wrap-around scrolling' (going from first-to-last, and last-to-first) is not possible.


Use the InfiniteViewPager in your Activity/Fragment layout:

	android:layout_height="fill_parent" />

Wrap your existing PagerAdapter with the InfinitePagerAdapter:

PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter);

Gradle build

To install the demo application to your device run the following task:

$ ./gradlew installDebug

To deploy the library to your local Maven repository run the following task:

$ ./gradlew install

Then, to use the library in your project add the following to your build.gradle:

dependencies {
    compile 'com.antonyt.infiniteviewpager:library:1.0.0'

Wrapped scrolling should now be possible with your ViewPager. The pages you see are not duplicates - each page from your PagerAdapter is only created once and then reused. This means you do not have to worry about managing multiple instances of the same Fragment.


It is only possible to achieve wrapping when you have at least 4 pages. This is because of the way the ViewPager creates, destroys, and displays the pages. No fix for the general case has been found.

Become a better Android Developer
Millions of developers are learning at MindOrks

Online Training Program

Featured Blogs

Our Team

MindOrks is Certainly one of the best online blog to stay on top of all the Android development news, coding and design patterns. Finally a blog I can count on to keep myself updated with latest and greatest things happening in Android world.

Vipul Shah
Android Developer

Become Pro in Android by watching videos