Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/antonyt/InfiniteViewPager
Augment Android's ViewPager with wrap-around functionality.
https://github.com/antonyt/InfiniteViewPager
Last synced: 2 months ago
JSON representation
Augment Android's ViewPager with wrap-around functionality.
- Host: GitHub
- URL: https://github.com/antonyt/InfiniteViewPager
- Owner: antonyt
- License: mit
- Created: 2012-03-11T16:44:58.000Z (almost 13 years ago)
- Default Branch: master
- Last Pushed: 2018-04-11T11:09:23.000Z (almost 7 years ago)
- Last Synced: 2024-08-03T01:24:28.087Z (6 months ago)
- Language: Java
- Homepage:
- Size: 129 KB
- Stars: 693
- Watchers: 27
- Forks: 194
- Open Issues: 31
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-android-ui - InfiniteViewPager - 环绕实现首页末页跳转 (ViewPager)
- awesome-android-ui - https://github.com/antonyt/InfiniteViewPager
README
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:
``` xml```
Wrap your existing `PagerAdapter` with the `InfinitePagerAdapter`:
``` java
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`:
```groovy
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.