Git Product home page Git Product logo

infiniteviewpager-1's Introduction

Infinite View Pager

Augment Android's ViewPager with wrap-around functionality. Original StackOverflow question: http://stackoverflow.com/questions/7546224/viewpager-as-a-circular-queue-wrapping

Problem

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.

Solution

Use the InfiniteViewPager in your Activity/Fragment layout:

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

Wrap your existing PagerAdapter with the InfinitePagerAdapter:

PagerAdapter wrappedAdapter = new InfinitePagerAdapter(adapter);
viewPager.setAdapter(wrappedAdapter);

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.

Caveats

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.

infiniteviewpager-1's People

Contributors

aeroechelon avatar antonyt avatar johnjohndoe avatar kongyang80 avatar ninjinkun avatar scottkennedy avatar yhirano avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.