InfiniteCycleViewPager

repository·master·Indexed 26 days ago

https://github.com/devlight/infinitecycleviewpager

An Android library providing a ViewPager with infinite cycling, supporting both horizontal and vertical orientations and interactive scaling effects. It includes features such as auto-scrolling, custom page transformation listeners, and XML configuration for scaling offsets and scroll durations. The library requires an item count greater than 2 for infinite scroll functionality and provides Xamarin bindings via NuGet.

Tokens
1.9K
Snippets
4
Records
14
Agent score
91%

What's inside InfiniteCycleViewPager

  1. Install InfiniteCycleViewPager via Gradle, Maven, or Ivy

    master

    You can integrate InfiniteCycleViewPager into your Android project using any of the following dependency managers:

    Gradle

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

    Maven

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

    Ivy

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

    Alternatively, you can download the .aar file from the GitHub releases page.

  2. Configure InfiniteCycleViewPager via XML

    master

    You can configure the HorizontalInfiniteCycleViewPager directly in your layout XML files using the following attributes:

    • app:icvp_interpolator: The interpolator for snap scrolling.
    • app:icvp_center_page_scale_offset: Offset from center when two pages appear.
    • app:icvp_max_page_scale: Maximum scale of the center top page.
    • app:icvp_medium_scaled: Whether scaling follows min -> medium -> max or just min -> max.
    • app:icvp_min_page_scale: Minimum scale of left and right bottom pages.
    • app:icvp_min_page_scale_offset: Offset from edge to minimum scaled pages.
    • app:icvp_scroll_duration: Duration of the snap scrolling.
    <!--<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"/>
  3. Initialize InfiniteCycleViewPager in Java

    master

    You can initialize either HorizontalInfiniteCycleViewPager or VerticalInfiniteCycleViewPager programmatically. The library supports setting scaling, offsets, scroll duration, and listeners via method calls.

    Note: Infinite scroll is only available when the item count is greater than 2. Two-way widgets require significant memory.

    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(...);
  4. Control InfiniteCycleViewPager programmatically

    master

    Use the following methods to interact with the ViewPager instance:

    • getRealItem(): Returns the current item position.
    • notifyDataSetChanged(): Updates the ViewPager after the adapter has been updated.
    • startAutoScroll(boolean positive): Starts auto-scrolling. Pass true for positive direction and false for negative direction.
    • stopAutoScroll(): Stops the auto-scrolling behavior.
  5. Configure InfiniteCycleViewPager via XML attributes

    master

    You can customize the visual behavior of the InfiniteCycleViewPager (or VerticalInfiniteCycleViewPager) directly in your layout XML files using the following attributes:

    • icvp_min_page_scale_offset: Dimension offset for the minimum scale pages.
    • icvp_center_page_scale_offset: Dimension offset for the center (maximum scale) page.
    • icvp_min_page_scale: Float value for the minimum scale of side pages.
    • icvp_max_page_scale: Float value for the maximum scale of the center page.
    • icvp_medium_scaled: Boolean to enable/disable medium scaling (interpolating between min and max scale).
    • icvp_scroll_duration: Integer duration for the snapping scroll animation.
    • icvp_page_duration: Integer duration for auto-scrolling transitions.
    • icvp_interpolator: Resource ID of an Android Interpolator to control scroll easing.
  6. Control auto-scrolling in InfiniteCycleViewPager

    master

    The InfiniteCycleManager provides methods to enable or disable automatic page cycling.

    • startAutoScroll(boolean isAutoScrollPositive): Starts the auto-scroll loop. If isAutoScrollPositive is true, it scrolls forward; if false, it scrolls backward.
    • stopAutoScroll(): Stops the auto-scroll loop.
  7. Set an adapter for InfiniteCycleViewPager

    master

    To enable infinite cycling, pass your PagerAdapter to the setAdapter() method of the manager.

    Note: The manager only wraps the adapter in an InfiniteCyclePagerAdapter if the adapter's item count is at least 3 (MIN_CYCLE_COUNT). If the count is less than 3, the original adapter is returned without infinite cycling logic.

  8. Wrap a PagerAdapter with InfiniteCyclePagerAdapter

    master
    To enable infinite scrolling in a ViewPager, wrap your existing PagerAdapter with InfiniteCyclePagerAdapter. This wrapper uses a large virtual item count (10,000,000) to simulate an infinite loop. The internal logic maps the virtual position back to the real position of your original adapter using a modulo operation.