Bounce Effect On Recyclerview
Solution 1:
I also couldn't find any library that supports the bounce effect for RecyclerView. Eventually I ended up implementing a new library by myself. Check out my library overscroll-bouncy-android. . It currently supports RecyclerView with LinearLayoutManager. I'm also working on ListView and ScrollView.
To use my library:
Step 1:
dependencies {
compile'com.chauthai.overscroll:overscroll-bouncy:0.1.0'
}
Step 2:
<com.chauthai.overscroll.RecyclerViewBouncy
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
Solution 2:
This can be easily done with dynamic animations without using any third-party library. I wrote an article about this here.
Another advantage is that it'll work with any type of layout manager and since we are using dynamic animations which are physics-based so animation feels more natural.
Solution 3:
You can use this library https://github.com/EverythingMe/overscroll-decor So, you need to create your own ScrollDecorAdapter like this
publicclassCustomRecyclerViewOverScrollDecorAdapterextendsRecyclerViewOverScrollDecorAdapter {
RecyclerView mRecyclerView;
publicCustomRecyclerViewOverScrollDecorAdapter(RecyclerView recyclerView) {
super(recyclerView);
mRecyclerView = recyclerView;
}
@OverridepublicbooleanisInAbsoluteEnd() {
LinearLayoutManagerlinearLayoutManager= (LinearLayoutManager) mRecyclerView.getLayoutManager();
if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
return !mRecyclerView.canScrollHorizontally(1);
} else {
return !mRecyclerView.canScrollVertically(1);
}
}
}
And now in your fragment/activity use
CustomVerticalOverScrollDecoratoroverScrollDecorator=newCustomVerticalOverScrollDecorator(newCustomRecyclerViewOverScrollDecorAdapter(yourRecyclerView));
Where CustomVerticalOverScrollDecorator smth like this
publicclassCustomVerticalOverScrollDecoratorextendsVerticalOverScrollBounceEffectDecorator {
publicCustomVerticalOverScrollDecorator(IOverScrollDecoratorAdapter viewAdapter) {
this(viewAdapter, DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD, DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK, DEFAULT_DECELERATE_FACTOR);
}
publicCustomVerticalOverScrollDecorator(IOverScrollDecoratorAdapter viewAdapter, float touchDragRatioFwd, float touchDragRatioBck, float decelerateFactor) {
super(viewAdapter, touchDragRatioFwd, touchDragRatioBck, decelerateFactor);
// Some setup on the view itself.
}
}
Solution 4:
You can try my library https://github.com/Valkriaine/Bouncy.
It supports both recyclerview and nestedscrollview.
In your app module build.gradle:
dependencies {
implementation 'androidx.recyclerview:recyclerview:1.1.0'
implementation 'com.factor:bouncy:1.8'
}
And use it as a normal recyclerview.
<com.factor.bouncy.BouncyRecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:recyclerview_fling_animation_size=".7"
app:recyclerview_overscroll_animation_size=".7"
app:recyclerview_damping_ratio="DAMPING_RATIO_LOW_BOUNCY"
app:recyclerview_stiffness="STIFFNESS_MEDIUM"
app:allow_drag_reorder="true"
app:allow_item_swipe="false"/>
Setup adapter and layoutmanager. Technically supports any layoutmanager:
recycler_view.setAdapter(myAdapter);
recycler_view.setLayoutManager(new LinearLayoutManager(context));
//recycler_view.setLayoutManager(new GridLayoutManager(context, 3));
Horizontal overscroll too:
recycler_view.setLayoutManager(newLinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
If the bounce animation is in the wrong direction (eg bouncing horizontally while the layout is vertical) you can also manually set the animation orientation:
recycler_view.setOrientation(LinearLayoutManager.VERTICAL);
Post a Comment for "Bounce Effect On Recyclerview"