InfiniteCycleViewPager
repository·master·Indexed 26 days ago
https://github.com/devlight/infinitecycleviewpagerAn 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.
What's inside InfiniteCycleViewPager
- Xamarin bindings for this library are available via NuGet. You can find the plugin at: Xam.Plugins.Android.InfiniteCycleViewPager.
Install InfiniteCycleViewPager via Gradle, Maven, or Ivy
masterYou 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
.aarfile from the GitHub releases page.Configure InfiniteCycleViewPager via XML
masterYou can configure the
HorizontalInfiniteCycleViewPagerdirectly 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"/>Initialize InfiniteCycleViewPager in Java
masterYou can initialize either
HorizontalInfiniteCycleViewPagerorVerticalInfiniteCycleViewPagerprogrammatically. 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(...);Control InfiniteCycleViewPager programmatically
masterUse 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. Passtruefor positive direction andfalsefor negative direction.stopAutoScroll(): Stops the auto-scrolling behavior.
Configure InfiniteCycleViewPager via XML attributes
masterYou can customize the visual behavior of the
InfiniteCycleViewPager(orVerticalInfiniteCycleViewPager) 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 AndroidInterpolatorto control scroll easing.
Control auto-scrolling in InfiniteCycleViewPager
masterThe
InfiniteCycleManagerprovides methods to enable or disable automatic page cycling.startAutoScroll(boolean isAutoScrollPositive): Starts the auto-scroll loop. IfisAutoScrollPositiveistrue, it scrolls forward; iffalse, it scrolls backward.stopAutoScroll(): Stops the auto-scroll loop.
Set a custom PageTransform listener
masterYou can intercept the page transformation process by providing anOnInfiniteCyclePageTransformListener. This allows you to execute code before or after the internal scaling and translation transformations are applied to a page.Update data in InfiniteCycleViewPager
masterWhen your underlying data changes, callnotifyDataSetChanged()on theInfiniteCycleManager. This ensures that both theInfiniteCyclePagerAdapterand the internalPageTransformerare updated to reflect the new item count and positions.Get the real item position from the original adapter
masterBecause theInfiniteCyclePagerAdapteruses a virtual count to achieve infinite cycling,viewPager.getCurrentItem()returns a virtual position. To get the actual index of the item from your original data set, usegetRealItem().Set an adapter for InfiniteCycleViewPager
masterTo enable infinite cycling, pass your
PagerAdapterto thesetAdapter()method of the manager.Note: The manager only wraps the adapter in an
InfiniteCyclePagerAdapterif 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.Wrap a PagerAdapter with InfiniteCyclePagerAdapter
masterTo enable infinite scrolling in aViewPager, wrap your existingPagerAdapterwithInfiniteCyclePagerAdapter. 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.