An android ViewPager extension allowing infinite scrolling

Overview

NO LONGER MAINTAINED

LoopingViewPager

An android ViewPager extension allowing infinite scrolling.

You can use it with "standart" PagerAdapter (inflating the pager with Views),
but you can also use FragmentPagerAdapter which allows you to fill the pager with Fragments!

The ViewPager will actually create 2 additional Views/Fragments to fake the infinite loop.

This ViewPager is fully compatible with ViewPagerIndicator, and PagerSlidingTabStrip!

Usage

To use it simply change <android.support.v4.view.ViewPager> to <com.imbryk.viewPager.LoopViewPager>

If your PagerAdapter is used only to create Views (i.e. you don't use FragmentPagerAdapter or FragmentStatePagerAdapter), then no more code changes are needed!

If you want to use LoopViewPager with FragmentPagerAdapter or FragmentStatePagerAdapter additional changes in the adapter must be done.
The adapter must be prepared to create 2 extra items e.g.:

  • The original adapter creates 4 items: [0,1,2,3]
  • The modified adapter will have to create 6 items [0,1,2,3,4,5]
  • with mapping realPosition=(position-1)%count
  • [0->3, 1->0, 2->1, 3->2, 4->3, 5->0]

Sometimes "blinking" can be seen when paginating to first or last view (e.g. when you have a NetworkImageView in your layout). To remove this effect, simply call setBoundaryCaching( true ) on your LoopViewPager, or change DEFAULT_BOUNDARY_CASHING to true, if you want to set boundary caching on all LoopViewPager instances. This will prevent the first and last element from being destroyed, and every time they need to be displayed the existing instances will be used.

Sample

You can see a sample usage on ViewPagerIndicator fork (by Jake Wharton)
or on PagerSlidingTabStrip fork (by Andreas Stütz)

License

Copyright 2013 Leszek Mzyk

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.
Comments
  • Fixed zero division exception in case no data in adapter. Added gradle support.

    Fixed zero division exception in case no data in adapter. Added gradle support.

    Zero division exception is thrown when viewpager and adapter are created, and there is no data in adapter (it appears later, e.g. loaded from internet). Viewpager adapter's wrapper tries to determine realPosition but fails. Also added gradle support

    opened by kboyarshinov 5
  • NotifyDataSetChanged

    NotifyDataSetChanged

    Hi,

    I'm wondering if there is a special way to notify the adapter with this lib ? The readme specifie two adapter, can we get access to the second one ?

    opened by marshallino16 1
  • Allow empty adapter

    Allow empty adapter

    Make wrapping adapter empty when the wrapped adapter is empty. Before when the wrapped adapter returned 0 from getCount(), signaling that it doesn't want to create any pages, the wrapping adapter returned 2. Because of that view pager could still call instantiateItem(). In my case my wrapped adapter wasn't ready at all to run instantiateItem() while getCount() returned 0 and it crashed. Thanks to this change view pager is blank until I add some data, which is exactly what I expect.

    opened by marcin-kozinski 0
  • Added Delegate for setPrimaryItems

    Added Delegate for setPrimaryItems

    Fragment with a FragmentPagerAdapter will now have setUserVisibleHint called when shown.

    Based on this StackOverflowQuestion: http://stackoverflow.com/questions/10024739/how-to-determine-when-fragment-becomes-visible-in-viewpager

    The PagerAdapter should forward and delegate the setPrimaryItem to allow for FragmentPagerAdapter to call the setUserVisibleHint methods to true.

    opened by AlexandreArpin 0
  • How to use tab layout with Looping View Pager.

    How to use tab layout with Looping View Pager.

    When use it my app do crash: Here is my code :

    tablayout.setupWithViewPager(mLoopingViewPager);

    Here is my logcat:

    App has crashed, executing CustomActivityOnCrash's UncaughtExceptionHandler java.lang.IndexOutOfBoundsException: Invalid index 4, size is 1 at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255) at java.util.ArrayList.get(ArrayList.java:308) at android.support.design.widget.TabLayout.getTabAt(TabLayout.java:518) at android.support.design.widget.TabLayout$TabLayoutOnPageChangeListener.onPageSelected(TabLayout.java:1986) at android.support.v4.view.ViewPager.dispatchOnPageSelected(ViewPager.java:1867) at android.support.v4.view.ViewPager.scrollToItem(ViewPager.java:629) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:609) at android.support.v4.view.ViewPager.setCurrentItemInternal(ViewPager.java:570) at android.support.v4.view.ViewPager.setCurrentItem(ViewPager.java:562) at com.imbryk.viewPager.LoopViewPager.setCurrentItem(LoopViewPager.java:110)

    opened by chubecode 0
  • Bug: When I use addOnPageChangeListener instead setOnPageChangeListener, it will lead to some unpredictable problems.

    Bug: When I use addOnPageChangeListener instead setOnPageChangeListener, it will lead to some unpredictable problems.

    When I use addOnPageChangeListener instead setOnPageChangeListener, it will lead to some unpredictable problems. Add the following code to fix it in LoopViewPager:: 【当我使用addOnPageChangeListener代替setOnPageChangeListener,这将导致一些不可预知的问题。在LoopViewPager中添加以下代码作简单的修复:】

        @Deprecated
        @Override
        public void addOnPageChangeListener(OnPageChangeListener listener) {
            // only support one listener, use setOnPageChangeListener instead
            mOuterPageChangeListener = listener;
        }
    
    opened by liyujiang-gzu 0
  • How to Cache PagerAdapter Item

    How to Cache PagerAdapter Item

    public class SimpleGalleryAdapter extends PagerAdapter {

    private List<T> mDatas;
    private String imgFieldName;
    private SparseArray<ImageView> mCaches = new SparseArray<>();
    private String host;
    private OnImageLoadListener<T> mListener;
    
    @Override
    public int getCount() {
        return EmptyUtils.emptyOfList(mDatas) ? 0 : mDatas.size();
    }
    
    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    
    @Override
    public Object instantiateItem(ViewGroup container, int position) {
    
        Context context = container.getContext();
        ImageView img_display = mCaches.get(position);
    
        if (img_display == null) {
            img_display = new ImageView(context);
            img_display.setScaleType(ImageView.ScaleType.CENTER_CROP);
            mCaches.put(position, img_display);
        }
    
        T mItem = mDatas.get(position);
    
        if (mListener != null) {
             mListener.onImageLoad(img_display, mItem, imgFieldName, host);
        }
        container.addView(img_display);
        return img_display;
    }
    
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        if (mCaches.keyAt(position) != -1) {
            container.removeView(mCaches.get(position));
            mCaches.remove(position);
        }
    }
    
    public SimpleGalleryAdapter(List<T> mDatas, String host, String imgFieldName, OnImageLoadListener<T> mListener) {
        this.mDatas = mDatas;
        this.imgFieldName = imgFieldName;
        this.host = host;
        this.mListener = mListener;
    }
    
    public SimpleGalleryAdapter(List<T> mDatas, String host, String imgFieldName) {
        this.mDatas = mDatas;
        this.imgFieldName = imgFieldName;
        this.host = host;
        this.mListener = new GlideImageLoader<T>();
    }
    

    }

    that is my adapter , I user ViewPager no error , but use LoopViewPager throw this error The specified child already has a parent. You must call removeView() on the child's parent first.

    opened by SingleJie 0
  • Crash when calling MyPagerAdapter.notifyDataSetChanged()

    Crash when calling MyPagerAdapter.notifyDataSetChanged()

    The application's PagerAdapter changed the adapter's contents without calling PagerAdapter#notifyDataSetChanged! Expected adapter item count: 6, found: 2

    opened by TracyZhangLei 6
Owner
Leszek Mzyk
Leszek Mzyk
UltraViewPager is an extension for ViewPager to provide multiple features in a single ViewPager.

UltraViewPager 中文文档 ProjectUltraViewPager is a ViewPager extension that encapsulates multiple features, mainly to provide a unified solution for multi

Alibaba 5k Dec 20, 2022
Pixplicity 915 Nov 8, 2022
Library containing common animations needed for transforming ViewPager scrolling for Android v13+.

ViewPagerTransforms Library containing common animations needed for transforming ViewPager scrolling on Android v13+. This library is a rewrite of the

Ian Thomas 2.5k Dec 31, 2022
A custom ViewPager title strip which gives continuous feedback to the user when scrolling

SmartTabLayout A custom ViewPager title strip which gives continuous feedback to the user when scrolling. This library has been added some features an

ogaclejapan 7k Jan 1, 2023
Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. With Kotlin support!

Don't write a ViewPager Adapter! Hook up your ViewPager to your data model using Android Data Binding Framework. Show some ❤️ ?? Sweet and short libra

Rakshak R.Hegde 180 Nov 18, 2022
Persons cards list viewpager - Persons cards list viewpager using kotlin

persons_cards_list_viewpager Дизайн и условие взяты из https://github.com/appKOD

Mironov Ury 1 Mar 1, 2022
A simple keyframe-based animation framework for UIKit. Perfect for scrolling app intros.

Jazz Hands is a simple keyframe-based animation framework for UIKit. Animations can be controlled via gestures, scroll views, KVO, or ReactiveCocoa. J

IFTTT 6.4k Dec 30, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 3, 2023
Augment Android's ViewPager with wrap-around functionality.

Infinite View Pager Augment Android's ViewPager with wrap-around functionality. Original StackOverflow question: http://stackoverflow.com/questions/75

Antony Tran 692 Dec 14, 2022
[Development stopped in 2014. Unfinished and not stable - not recommended to use.] An easy-to-use ViewPager subclass with parallax background effect for Android apps.

Development stopped in 2014 Not developed since 2014. Unfinished and not stable - not recommended to use. ParallaxViewPager An easy-to-use ViewPager s

Andras Kindler 437 Dec 29, 2022
Android - A ViewPager page indicator that displays the current page number and (optionally) the page count

NumericPageIndicator A ViewPager page indicator that displays the current page number and (optionally) the page count. It can also display buttons to

Manuel Peinado Gallego 253 Nov 16, 2022
Android ViewPager template with cool animation.

glazy-viewpager ViewPager template with cool animation. Preview Dependencies compile 'com.android.support:palette-v7:25.2.0' Usage Refer the implement

Kannan Anbarasan 251 Nov 29, 2022
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock.

Android ViewPagerIndicator Paging indicator widgets that are compatible with the ViewPager from the Android Support Library to improve discoverability

Jake Wharton 10.2k Jan 5, 2023
Android Parallax-ViewPager

ParallaxViewPager Demo Usage <com.github.ybq.parallaxviewpager.ParallaxViewPager android:id="@+id/viewpager" android:layout_width="ma

ybq 588 Nov 29, 2022
Endless full-screen card ViewPager inspired by apple iBook for Android

FullScreenCardViewPager for Android Endless full-screen card ViewPager inspired by apple iBook for Android. ✅ We are open to any new feature request,

Iman Dolatkia 136 Dec 16, 2022
A Material Design ViewPager easy to use library

MaterialViewPager Material Design ViewPager easy to use library Sample And have a look on a sample Youtube Video : Youtube Link Download In your modul

Florent CHAMPIGNY 8.2k Dec 29, 2022
A different beautiful ViewPager, with quick swipe controls

HollyViewPager Usage Add a HollyViewPager in your layout <com.github.florent37.hollyviewpager.HollyViewPager android:id="@+id/hollyViewPager"

Florent CHAMPIGNY 1.1k Dec 9, 2022
An interactive indicator to navigate between the different pages of a ViewPager

Android PagerSlidingTabStrip (default Material Design) This library is not maintained anymore and there will be no further releases. For most of the c

JPARDOGO 2.2k Jan 4, 2023
Combine ViewPager and Animations to provide a simple way to create applications' guide pages.

WoWoViewPager WoWoViewPager combines ViewPager and Animations to provide a simple way to create applications' guide pages. When users are dragging WoW

黄伟平 2.7k Dec 30, 2022