Infinite Scrolling Image ViewPager

I had the same problem, but I was able to find a way to solve it – the code can be found on github.

If you copy the classes InfiniteViewPager and InfinitePagerAdapter into your project, you can achieve infinite (wrapped) scrolling with some small changes.

In your Activity, wrap your PagerAdapter with an InfinitePagerAdapter:

PagerAdapter adapter = new InfinitePagerAdapter(new ImagePagerAdapter(this, imageArra, stringArray));

Change the ViewPager in the activity XML to be an InfiniteViewPager:

<com.antonyt.infiniteviewpager.InfiniteViewPager 
       android:id="@+id/myimagepager" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" />

You can rename the classes to whatever you want. This code only works if you have at least three pages (you have nine in your example code, so it will work fine for that).

Leave a Comment