Android auto scroll viewpager or viewpager in viewpager

Overview

Android Auto Scroll ViewPager

ViewPager which can auto scrolling, cycling, decelerating.
ViewPager which can be slided normal in parent ViewPager.

Attention: This library is too old and only supports android-support lib, It's deprecated now. The latest Kotlin and AndroidX support version can use https://github.com/pzienowicz/androidx-auto-scroll-view-pager, Thanks to pzienowicz for giving it a new life.

Dev Tools App

The Dev Tools App is a powerful android development tool that can help you improve efficiency greatly, It can be used to view the latest open source projects, view activity history, view manifest, decompile, color picker, extract apk or so, view app info, open or close the options in the developer options quickly, and more.

You can download it from DevTools@Google Play.

中文介绍见: Android自动滚动 轮播循环的ViewPager android-auto-scroll-view-pager

Sample Application

Download

Demo File: AutoScrollViewPagerSingleDemo.java
Demo Project: android-demo

Usage

  • include this library, use
<cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager
	android:id="@+id/view_pager"
	android:layout_width="match_parent"
	android:layout_height="wrap_content" />

replace

<android.support.v4.view.ViewPager
	android:id="@+id/view_pager"
	android:layout_width="match_parent"
	android:layout_height="wrap_content" />
  • startAutoScroll() start auto scroll, delay time is getInterval().
  • startAutoScroll(int) start auto scroll delayed.
  • stopAutoScroll() stop auto scroll.

Setting

  • setInterval(long) set auto scroll time in milliseconds, default is DEFAULT_INTERVAL.
  • setDirection(int) set auto scroll direction, default is RIGHT.
  • setCycle(boolean) set whether automatic cycle when auto scroll reaching the last or first item, default is true.
  • setScrollDurationFactor(double) set the factor by which the duration of sliding animation will change.
  • setSlideBorderMode(int) set how to process when sliding at the last or first item, default is SLIDE_BORDER_MODE_NONE.
  • setStopScrollWhenTouch(boolean) set whether stop auto scroll when touching, default is true.
  • setBorderAnimation(boolean) set whether animating when auto scroll at the last or first item, default is true.
  • You cannot combine with ViewPagerIndicator if setCycle(true).
  • If you want infinite loop, please see AutoScrollViewPagerSingleDemo.java
    More: http://www.trinea.cn/android/auto-scroll-view-pager/

Proguard

-keep class cn.trinea.android.** { *; }
-keepclassmembers class cn.trinea.android.** { *; }
-dontwarn cn.trinea.android.**

Download

Maven:

<dependency>
    <groupId>cn.trinea.android.view.autoscrollviewpager</groupId>
    <artifactId>android-auto-scroll-view-pager</artifactId>
    <version>1.1.2</version>
</dependency>

Gradle:

compile ('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') {
    exclude module: 'support-v4'
}

About Me

Author of Android Dev Tools App

License

Copyright 2014 trinea.cn

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
  • don't consume touch event when scroll up or down

    don't consume touch event when scroll up or down

    Hi , first Thanks for your library.

    I want to put auto-scroll-view-pager as header of my listview (RecyclerView) but When I scroll up/down it consume touch event. I use following piece of code to handle this issue (I put it in dispatchTouchEvent method ):

    
        @Override
        public boolean dispatchTouchEvent(MotionEvent ev) {
            int action = MotionEventCompat.getActionMasked(ev);
    
            if (stopScrollWhenTouch) {
                if ((action == MotionEvent.ACTION_DOWN) && isAutoScroll) {
                    isStopByTouch = true;
                    stopAutoScroll();
                } else if (ev.getAction() == MotionEvent.ACTION_UP && isStopByTouch) {
                    startAutoScroll();
                }
            }
    
            if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT || slideBorderMode == SLIDE_BORDER_MODE_CYCLE) {
                touchX = ev.getX();
                if (ev.getAction() == MotionEvent.ACTION_DOWN) {
                    downX = touchX;
                }
                int currentItem = getCurrentItem();
                PagerAdapter adapter = getAdapter();
                int pageCount = adapter == null ? 0 : adapter.getCount();
                /**
                 * current index is first one and slide to right or current index is last one and slide to left.<br/>
                 * if slide border mode is to parent, then requestDisallowInterceptTouchEvent false.<br/>
                 * else scroll to last one when current item is first one, scroll to first one when current item is last
                 * one.
                 */
                if ((currentItem == 0 && downX <= touchX) || (currentItem == pageCount - 1 && downX >= touchX)) {
                    if (slideBorderMode == SLIDE_BORDER_MODE_TO_PARENT) {
                        getParent().requestDisallowInterceptTouchEvent(false);
                    } else {
                        if (pageCount > 1) {
                            setCurrentItem(pageCount - currentItem - 1, isBorderAnimation);
                        }
                        getParent().requestDisallowInterceptTouchEvent(true);
                    }
                    return super.dispatchTouchEvent(ev);
                }
            }
           //----------------this is my code ----------------
            boolean consumeTouch = false;
            if (action == MotionEvent.ACTION_DOWN) {
                touchY = ev.getY();
            } else if (action == MotionEvent.ACTION_UP) {
                consumeTouch = Math.abs(touchY - ev.getY()) > 0;
            }
            if (consumeTouch)
                getParent().requestDisallowInterceptTouchEvent(true);
            else
                getParent().requestDisallowInterceptTouchEvent(false);
    
    
            return super.dispatchTouchEvent(ev);
        }
    

    It's work somehow but have issue. When I scroll up/down autoScroll mode not worked. Can you help me to solve this issue ?

    opened by hadifar 5
  • Scroll and Stop vs. Flinging

    Scroll and Stop vs. Flinging

    When trying to scroll and stop to the left (contrary to flingin) the pager moves 1 page on the opposite side, if not to the other. It's an strange behavior. Could you pleas take a look at it.

    opened by fxsalazar 3
  • Vertical Scroll not working inside scrollview

    Vertical Scroll not working inside scrollview

    when view pager is added in a scrollview and try to scroll vertically on dragging over view pager not works, one has to vertical scroll below view pager to scroll down.

    opened by akslive 2
  • app:dexDebug错误

    app:dexDebug错误

    遇到这么一个错误 Error:Execution failed for task ':app:dexDebug'.

    com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command 'C:\Program Files\Java\jdk1.8.0_25\bin\java.exe'' finished with non-zero exit value 2

    不过不知道跟别的哪个库有冲突了 这是我的gradle.build dependencies { compile fileTree(dir: 'libs', include: ['*.jar'])

    // Google stuff
    compile 'com.android.support:appcompat-v7:22.1.0'
    
    // Square-y stuff
    compile 'com.squareup.retrofit:retrofit:1.9.0'
    compile 'com.squareup.okhttp:okhttp:2.2.0'
    compile 'com.squareup:otto:1.3.5'
    compile 'com.squareup.picasso:picasso:2.5.2'
    compile 'cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2'
    compile 'com.squareup.dagger:dagger:1.2.1'
    provided 'com.squareup.dagger:dagger-compiler:1.2.1'
    
    // UI stuff
    compile 'com.jakewharton:butterknife:5.1.2'
    compile 'com.nispok:snackbar:2.7.5'
    compile 'com.marshalchen.ultimaterecyclerview:library:0.3.6'
    compile 'com.github.lecho:hellocharts-library:1.5.5@aar'
    
    // Unit tests
    testCompile 'com.android.support.test:testing-support-lib:0.1'
    testCompile 'org.mockito:mockito-core:1.9.0'
    

    }

    opened by kingaza 2
  • 编译失败

    编译失败

    你好,我在用Gradle添加该库时,编译不能通过,错误信息:

    Error:Execution failed for task ':app:dexDebug'.
    > com.android.ide.common.internal.LoggedErrorException: Failed to run command:
        D:\android\sdk\build-tools\21.0.2\dx.bat --dex --no-optimize --output D:\Android\app\build\intermediates\dex\debug --input-list=D:\Android\app\build\intermediates\tmp\dex\debug\inputList.txt
    Error Code:
        2
    Output:
        UNEXPECTED TOP-LEVEL EXCEPTION:
        com.android.dex.DexException: Multiple dex files define Landroid/support/v4/accessibilityservice/AccessibilityServiceInfoCompat$AccessibilityServiceInfoVersionImpl;
            at com.android.dx.merge.DexMerger.readSortableTypes(DexMerger.java:596)
            at com.android.dx.merge.DexMerger.getSortedTypes(DexMerger.java:554)
            at com.android.dx.merge.DexMerger.mergeClassDefs(DexMerger.java:535)
            at com.android.dx.merge.DexMerger.mergeDexes(DexMerger.java:171)
            at com.android.dx.merge.DexMerger.merge(DexMerger.java:189)
            at com.android.dx.command.dexer.Main.mergeLibraryDexBuffers(Main.java:454)
            at com.android.dx.command.dexer.Main.runMonoDex(Main.java:302)
            at com.android.dx.command.dexer.Main.run(Main.java:245)
            at com.android.dx.command.dexer.Main.main(Main.java:214)
            at com.android.dx.command.Main.main(Main.java:106)
    

    搜索后,应该是包重复了(应该是v4包),我依赖的包:

    dependencies {
        compile fileTree(dir: 'libs', include: ['*.jar'])
        compile 'com.android.support:support-v4:21.0.2'
        compile 'com.jakewharton:butterknife:6.0.0'
        compile 'com.google.code.gson:gson:2.3.1'
        compile 'de.greenrobot:eventbus:2.4.0'
        compile 'com.nostra13.universalimageloader:universal-image-loader:1.9.3'
        compile 'it.sephiroth.android.library.imagezoom:imagezoom:+'
    }
    libs目录下是 ActiveAndroid和Volley的2个包
    

    谢谢。

    opened by deviltsw 2
  • That lib has support Indicator

    That lib has support Indicator

    Hi trinea, I'm using your lib , when I combined with https://github.com/ongakuer/CircleIndicator . not working fine . That's my code

    viewPager = (AutoScrollViewPager) findViewById(R.id.view_pager); viewPager.setAdapter(new ImagePagerAdapter(this, imageUrl).setInfiniteLoop(true)); viewPager.setInterval(3000); viewPager.startAutoScroll(); viewPager.setCurrentItem(1); CircleIndicator indicator = (CircleIndicator) view.findViewById(R.id.indicator); indicator.setViewPager(viewpager); So could u help me ?

    opened by ridojito 0
  • Fixing memory leak resulting from nonstatic Handler inner class. When sw...

    Fixing memory leak resulting from nonstatic Handler inner class. When sw...

    ...itching contexts, android.os.Message objects sent to previously instantiated handlers were holding references to target handler, hence holding a reference to its outer class, and thus leaking the caller activity.

    opened by leonardoaramaki 0
  • 为ViewPager的子View添加事件后,长按屏幕AutoScroll无法stop

    为ViewPager的子View添加事件后,长按屏幕AutoScroll无法stop

    群主好啊,最近使用你的AutoViewPager的时候,发现了一个小问题。 通常当手指按住屏幕的时候,是可以暂停滑动的。当我为ImageView(我的ViewPagerAdpter的Item是ImageView)设定了onClick事件的时候,用手指长按屏幕就无法暂停滑动了。

    我的理解是这样的: 根据View事件的分发机制,Event是从ViewPager的dispatchTouchEvent开始的,当在ViewPager的onInterceptTouchEvent中没有返回true,也就没有拦截事件的时候,就会分发到ImageView中,由于为ImageView设置了onClick事件,所以在onTouchevent里面会执行onClick事件,从而消费掉了该事件,因此事件就不会返回到ViewPager的onTouchEvent中,也就无法处理相应的逻辑了。

    我的解决方案是: 将ViewPager中onTouchEvent的逻辑放到dispatchTouchEvent或者onInterceptEvent中去,这样就可以先控制ViewPager,然后再将事件传递到ImageView,让其自行处理。

    上面的长按和onClick事件有点矛盾,下面是原因: 这里说下onClick和onLongClick,我通过log看到,即使你设置了onLongClick事件的处理,但是依旧会执行onClick事件,这是因为onLongClick事件默认返回了FALSE,事件没有消费掉,导致在action up的时候执行了onClick。所以也就是不管你是不是长按屏幕,都会执行onClick事件。也就是我长按屏幕时,事件被ImageView消费掉导致没法stop的原因。

    在实际开发中,应该避免onClick和onLongClick同时触发的情况,所以在onLongClick方法里面返回FALSE,就可以了。当然这和上面的问题关联不是很大。

    题外话: 看了下淘宝和携程还有网易音乐的广告栏 淘宝没有任何的限制,长按,或者move的时候,都可以继续轮循的。 携程的处理了move的情况,但没有处理长按的情况。 网易两种情况都处理了,并且onClick和onLongClick事件都响应了

    这是我结合ViewPagerIndicator和你的AutoScrollViewPager而成的项目:https://github.com/lightSky/InfiniteAutoScroolView

    opened by lightSky 0
  • Why i can't use this library..

    Why i can't use this library..

    Since I did migrate androidX, I can't use auto-scroll-view-pager library.

    i did implementation in build.gradle(app) file. like below code. implementation ('cn.trinea.android.view.autoscrollviewpager:android-auto-scroll-view-pager:1.1.2') { exclude module: 'support-v4' } also, i did sync project and clean code, rebuild. but i couldn't find 'cn.trinea.android.view.autoscrollviewpager.AutoScrollViewPager' in my xml.

    how can i solve it..?

    opened by pjs3065 1
  • "ViewPager" not found error when project migrated to AndroidX

    When I migrated my project to AndroidX it seems that "ViewPager" is not correctly referenced. When I separately try to create a ViewPager it's being referenced from "androidx.viewpager.widget", whereas in your library it is still referred from the support library as it pertains to the normal libraries and not AndroidX. Please provide an update or atleast a fix for this ASAP.

    Screenshot 2019-03-29 at 1 18 29 PM

    opened by sanketthecoder 5
  • Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

    Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'. > com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

    Error:Execution failed for task ':app:transformDexArchiveWithExternalLibsDexMergerForDebug'.

    com.android.builder.dexing.DexArchiveMergerException: Unable to merge dex

    opened by JYkim01 0
  •  I cannot scroll vertically when I  used it in a scrollView

    I cannot scroll vertically when I used it in a scrollView

    I cannot scroll vertically in the scope of this view when I used it inside a scrollView . But it can scroll vertically normally in a recyclerView. Who can help me

    opened by RaylanXL 0
Owner
Trinea
2021 滴滴、阿里内推可加我微信: trinea
Trinea
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
Persons cards list viewpager - Persons cards list viewpager using kotlin

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

Mironov Ury 1 Mar 1, 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
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
An android ViewPager extension allowing infinite scrolling

NO LONGER MAINTAINED LoopingViewPager An android ViewPager extension allowing infinite scrolling. You can use it with "standart" PagerAdapter (inflati

Leszek Mzyk 992 Nov 10, 2022
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 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
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
ViewPager that slides vertically.

ExpandablePager Layout that contains a ViewPager and can slide vertically between 2 states (expanded and collapsed). #Requirements Android 4.0+ (Ice C

Telenav Inc 716 Sep 15, 2022