An Android ViewPager that supports wrap-around of fragments.
Java Groovy
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
app
gradle/wrapper
.gitignore
InfiniteViewPager.iml
InfiniteViewPagerDemo.iml
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

InfiniteViewPager

An Android ViewPager that supports wrap-around of fragments.

imgur

The Problem

A regular ViewPager in Android does not support carousel-like scrolling of its items. We can scroll from the first item to the last item but not directly from the last item back to the first item and vice-versa. The InfiniteViewPager solves this issue with minimal code and no hacks.

The Source

  • InfiniteViewPager provides its own OnPageChangeListener. This listener performs circular rotation of the fragments in the ViewPager's adapter whenever a new page is selected.

  • InfiniteViewPagerAdapter simply stores a List of Fragments for the InfiniteViewPager.

Constraints

Wrap-around functionality only works if there are 3 or more fragments in the InfiniteViewPager. If the ViewPager has less than 3 fragments in it, the user can still swipe back and forth between the existing fragments just as in a normal ViewPager.