Infinite Cycle ViewPager Android Library

0
436
Infinite Cycle ViewPager Android Library
Infinite Cycle ViewPager Android Library

The ViewPager is the widget that allows the user to swipe left or right to see an entirely new screen. In a sense, it’s just a nicer way to show the user multiple tabs. It also has the ability to dynamically add and remove pages (or tabs) at anytime. In our previous article we discuss about some other viewPager like :

And today we’ll discuss about infinite cycle ViewPager with two-way orientation and interactive effect. You can see demo here ;

Infinite Cycle ViewPager demo
Infinite Cycle ViewPager demo

Lets go with implementation of Infinite Cycle ViewPager

Gradle:

compile 'com.github.devlight:infinitecycleviewpager:1.0.2'

Or Maven:

<dependency>
  <groupId>com.github.devlight</groupId>
  <artifactId>infinitecycleviewpager</artifactId>
  <version>1.0.2</version>
  <type>pom</type>
</dependency>

Or Ivy:

<dependency org='com.github.devlight' name='infinitecycleviewpager' rev='1.0.2'>
  <artifact name='$AID' ext='pom'></artifact>
</dependency>

Android SDK Version

InfiniteCycleViewPager requires a minimum SDK version of 11.

Parameters

For InfiniteCycleViewPager you can set such parameters as:

  • min scale:
    allows you to set the minimum scale of left and right bottom pages.
  • max scale:
    allows you to set the maximum scale of center top page.
  • min scale offset:
    allows you to set offset from edge to minimum scaled pages.
  • center scale offset:
    allows you to set offset from center when two pages appears.
  • model selected icon:
    allows you to set selected icon when current model is active.
  • medium scaled:
    allows you to set is scaling would be min -> max or min -> medium -> max.
  • scroll duration:
    allows you to set snap scrolling duration.
  • scroll interpolator:
    allows you to set snap scrolling interpolator.
  • page transform listener:
    allows you to set page transform listener.
  • auto scroll:
    allows you to set auto scroll in positive and negative directions.

Tips

  1. Two-way widget need a lot of memory.
  2. Infinite scroll available when item count more then 2.
  3. You can set vertical or horizontal infinite cycle ViewPager.

Init

Check out in code init:

//      final VerticalInfiniteCycleViewPager infiniteCycleViewPager =
//                (VerticalInfiniteCycleViewPager) view.findViewById(R.id.vicvp);
        final HorizontalInfiniteCycleViewPager infiniteCycleViewPager =
                (HorizontalInfiniteCycleViewPager) view.findViewById(R.id.hicvp);
        infiniteCycleViewPager.setAdapter(...);
        infiniteCycleViewPager.setScrollDuration(500);
        infiniteCycleViewPager.setInterpolator(...);
        infiniteCycleViewPager.setMediumScaled(true);
        infiniteCycleViewPager.setMaxPageScale(0.8F);
        infiniteCycleViewPager.setMinPageScale(0.5F);
        infiniteCycleViewPager.setCenterPageScaleOffset(30.0F);
        infiniteCycleViewPager.setMinPageScaleOffset(5.0F);
        infiniteCycleViewPager.setOnInfiniteCyclePageTransformListener(...);

If you want to get item position just call this method:

infiniteCycleViewPager.getRealItem();

To update your ViewPager after some adapter update or else, you can call this method:

infiniteCycleViewPager.notifyDataSetChanged();

If you want to start auto scroll or stop call this methods:

// true - positive
// false - negative
infiniteCycleViewPager.startAutoScroll(...);
infiniteCycleViewPager.stopAutoScroll();

Other methods check out in sample.

And XML init:

<!--<com.gigamole.infinitecycleviewpager.VerticalInfiniteCycleViewPager-->
<com.gigamole.infinitecycleviewpager.HorizontalInfiniteCycleViewPager
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:icvp_interpolator="..."
    app:icvp_center_page_scale_offset="30dp"
    app:icvp_max_page_scale="0.8"
    app:icvp_medium_scaled="true"
    app:icvp_min_page_scale="0.5"
    app:icvp_min_page_scale_offset="5dp"
    app:icvp_scroll_duration="500"/>

Download project

Hope you like this project. So please comment us!!!

Share your thoughts

Loading Facebook Comments ...
Loading Disqus Comments ...