yarolegovich /DiscreteScrollView

A scrollable list of items that centers the current element and provides easy-to-use APIs for cool item animations.

★ 5,766⑂ 771👁 93⑃ 22● 193▤ 2
JavaCreated 2017-03-03
下载:v1.5.1v1.5.1 ↓1.5.12020-08-01
+0
日增长
5,766
stars
771
forks
93
watchers
22
prs
193
issues
2
releases

README

DiscreteScrollView

The library is a RecyclerView-based implementation of a scrollable list, where current item is centered and can be changed using swipes.
It is similar to a ViewPager, but you can quickly and painlessly create layout, where views adjacent to the currently selected view are partially or fully visible on the screen. 

!GifSampleShop

 Gradle 
Add this into your dependencies block.

compile 'com.yarolegovich:discrete-scrollview:1.5.1'


 Reporting an issue

If you are going to report an issue, I will greatly appreciate you including some code which I can run to see the issue. By doing so you maximize the chance that I will fix the problem. 

By the way, before reporting a problem, try replacing DiscreteScrollView with a RecyclerView. If the problem is still present, it's likely somewhere in your code.

 Sample


Please see the sample app for examples of library usage.

!GifSampleWeather

 Wiki
 General
The library uses a custom LayoutManager to adjust items' positions on the screen and handle scroll, however it is not exposed to the client 
code. All public API is accessible through DiscreteScrollView class, which is a simple descendant of RecyclerView.

If you have ever used RecyclerView - you already know how to use this library. One thing to note - you should NOT set LayoutManager.

 Usage:
 1. Add DiscreteScrollView to your layout either using xml or code:
 2. Create your implementation of RecyclerView.Adapter. Refer to the sample for an example, if you don't know how to do it.
 3. Set the adapter.
 4. You are done! 
xml
  

java
DiscreteScrollView scrollView = findViewById(R.id.picker);
scrollView.setAdapter(new YourAdapterImplementation());


 API
 General
java
scrollView.setOrientation(DSVOrientation o); //Sets an orientation of the view
scrollView.setOffscreenItems(count); //Reserve extra space equal to (childSize  count) on each side of the view
scrollView.setOverScrollEnabled(enabled); //Can also be set using android:overScrollMode xml attribute

 Related to the current item:
java
scrollView.getCurrentItem(); //returns adapter position of the currently selected item or -1 if adapter is empty.
scrollView.scrollToPosition(int position); //position becomes selected
scrollView.smoothScrollToPosition(int position); //position becomes selected with animated scroll
scrollView.setItemTransitionTimeMillis(int millis); //determines how much time it takes to change the item on fling, settle or smoothScroll

 Transformations
One useful feature of ViewPager is page transformations. It allows you, for example, to create carousel effect. DiscreteScrollView also supports 
page transformations.
java
scrollView.setItemTransformer(transformer);

public interface DiscreteScrollItemTransformer {
    /
      In this method you apply any transform you can imagine (perfomance is not guaranteed).
      @param position is a value inside the interval [-1f..1f]. In idle state:
      |view1|  |currentlySelectedView|  |view2|
      -view1 and everyth

Top issues

Latest release

v1.5.1 v1.5.1 2020-08-01
Fixed incorrect ItemTransformer values
 Invoke onItemChanged callback when changed via scrollToPosition
 Allow disabling user scroll
 Made LayoutManager public so people can extend and modify its behavior

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON