A simple android infinite view pager
Table of Contents
Download the latest AAR from jitpack via Gradle:
-
Gradle
Project build.gradle
allprojects { repositories { ... maven { url 'https://jitpack.io' } } }
app module build.gradle
dependencies { implementation 'com.github.mahdidev78:infinitepager:TAG' }
-
Maven
Add the JitPack repository to your build file
<repositories> <repository> <id>jitpack.io</id> <url>https://jitpack.io</url> </repository> </repositories>
Add the dependency
<dependency> <groupId>com.github.mahdidev78</groupId> <artifactId>infinitepager</artifactId> <version>Tag</version> </dependency>
Add the ScrollToTop to your layout :
<com.mahdikh.vision.infinitepager.widget.InfinitePager
android:id="@+id/infinitePager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingStart="40dp"
android:paddingEnd="40dp"
app:currentItem="first"/>
Setup your code :
-
Kotlin
val pager = findViewById<InfinitePager>(R.id.infinitePager) pager.adapter = adapter // extends InfiniteAdapter
-
Java
InfinitePager pager = findViewById(R.id.infinitePager); pager.setAdapter(adapter); // extends InfiniteAdapter
-
kotlin
val callback: Callback = object : Callback { override fun onPageScrolled( position: Int, positionOffset: Float, positionOffsetPixels: Int ) { } override fun onPageSelected(position: Int) { } override fun onPageScrollStateChanged(state: Int) { } } pager.registerCallback(callback) // for register callback pager.unregisterCallback(callback) // for unregister callback pager.unregisterCallbacks() // unregister all calbacks
-
Java
Callback callback = new Callback() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageSelected(int position) { } @Override public void onPageScrollStateChanged(int state) { } }; pager.registerCallback(callback); // for register callback pager.unregisterCallback(callback); // for unregister callback pager.unregisterCallbacks(); // unregister all calbacks
attribute | Description | Options(examples) |
---|---|---|
currentItem | set the current item | first, center, last , 0, 1 , etc |
- Android KitKat 4.4+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Copyright 2021, mahdidev78
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Mahdi Khosravi - mahdi.khosravi.dev78@gmail.com
Project Link: https://github.com/mahdidev78/infinitepager