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
+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 everythTop issues
#204Library artifacts are published to jcenter only, which will close in 3 months16 comments · 2021-02-04#20Dependent on size of first item in adapter10 comments · 2017-05-10#217Caused by: org.gradle.internal.resolve.ModuleVersionNotFoundException: Could not find com.yarolegovich:discrete-scrollview:1.5.1.8 comments · 2024-09-10#70Dragging more than one page at a time8 comments · 2017-12-13#83Can support reverseLayout?7 comments · 2018-02-09#160Cannot set 'scaleX' to Float.NaN6 comments · 2019-01-23#153Spacing issue in vertical orientation6 comments · 2018-11-16#142`java.lang.IllegalArgumentException` on calling `scrollToPosition()`6 comments · 2018-09-25
Latest release
v1.5.1 v1.5.1 2020-08-01Fixed 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