yanzm / LoopViewPager

LoopViewPager for Android
Apache License 2.0
186 stars 44 forks source link

How to scroll from last to first by code? #4

Open yswheye opened 7 years ago

yswheye commented 7 years ago

How to scroll from last to first by code

esperia commented 7 years ago

I have same issue. +1

esperia commented 7 years ago

I wrote this code to LoopViewPager.java:

    public void next() {
        if (getCurrentItem() == mAdapter.getCount() - 1) {
            mPopulatePending = true;
            setCurrentItemInternal(0, true, true, -15000); // velocity is hard-coded
            ViewCompat.postInvalidateOnAnimation(this);
        } else {
            setCurrentItem(getCurrentItem() + 1, true);
        }
    }

Call:

mLoopViewPager.next();

It seems working. but the code has not been fully tested.

UPDATED(2017-08-03): I fixed a bug that it working only items <= 3(but it depends on page settings).