Giter Club home page Giter Club logo

loopingviewpager's Introduction

LoopingViewPager

Download

A ViewPager that supports infinite looping effect, smart auto-scroll, compatible with any indicators and easy to use. It especially uses it as banners of application with a simple item page.

Looping Viewpager can:

  • Plug and play, easy to use
  • Infinite Looping items
  • Auto scroll items, allow config, auto resume/pause when activity/fragment resume/pause
  • Won't scroll or loop if it has only 1 item
  • Compatible with many indicators

Demo app effect

Simple pager Pager with indicators

Sample app

You can download the apk for the sample app of this library at this link.

The code of the sample app is available at this link.

Having the sample apps installed is a good way to be notified of new releases. Although watching this repository will allow GitHub to email you whenever a new release is published.

Download

The Gradle dependency is available via jCenter. jCenter is the default Maven repository used by Android Studio.

The minimum API level supported by this library is API 16.

AndroidX

The latest version here Download

dependencies {
    implementation 'com.kenilt.loopingviewpager:loopingviewpager:0.2.0'
}

Usage

Simple usage

Just replace your ViewPager with LoopingViewPager and use it as normal

// Just set adapter and indicator as a normal view pager
vpPager.adapter = adapter
indicator.setViewPager(vpPager)
XML Properties
<com.kenilt.loopingviewpager.widget.LoopingViewPager
	android:id="@+id/vpPager"
	android:layout_width="match_parent"
	android:layout_height="match_parent"
	android:overScrollMode="never"/>
Advanced usage
// set adapter for view pager
vpPager.adapter = adapter

// when your adapter is FragmentPagerAdapter or FragmentStatePagerAdapter,
// use this function for better performance
vpPager.setAdapter(adapter, supportFragmentManager)

// set view pager for indicator
indicator.setViewPager(vpPager)

// active auto scroll
val autoScroller = AutoScroller(vpPager, lifecycle, 3000)
// pause auto scroll
autoScroller.isAutoScroll = false

If your adapter is instance of FragmentPagerAdapter or FragmentStatePagerAdapter, you should to use vpPager.setAdapter(adapter, supportFragmentManager) to get better performance, if not, LoopingViewPager will use reflection to get fragmentManager from your adapter to do its job.
By default, LoopingViewPager will force use behavior of FragmentPagerAdapter and FragmentStatePager adapter to BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT, because BEHAVIOR_SET_USER_VISIBLE_HINT is deprecated now.

AutoScroller is a separate class, so if you want your pager/banners auto-scroll, just create an AutoScroller(vpPager) and it will automatically scroll your pager/banners every scrollInterval (default is 5000 milliseconds).
If you want AutoScroller auto resume when Activity/Fragment resumed, and auto pause when Activity/Fragment paused, pass lifecyle as a parameter when created it AutoScroller(vpPager, lifecycle).
To change interval time, just call autoScroller.scrollInterval = value.
To resume/pause auto scroller, just call autoScroller.isAutoScroll = true/false

Credits

License

The MIT License

Copyright (c) 2020 Kenilt Nguyen

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

loopingviewpager's People

Contributors

kenilt avatar emitchel 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.