I want to use a bounce effect on a RecyclerView
. A bounce effect whenever I overscroll the content...
Does there exist a library or example for it?
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(new LinearLayoutManager(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);
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"/>
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.
You can use this library https://github.com/EverythingMe/overscroll-decor So, you need to create your own ScrollDecorAdapter like this
public class CustomRecyclerViewOverScrollDecorAdapter extends RecyclerViewOverScrollDecorAdapter {
RecyclerView mRecyclerView;
public CustomRecyclerViewOverScrollDecorAdapter(RecyclerView recyclerView) {
super(recyclerView);
mRecyclerView = recyclerView;
}
@Override
public boolean isInAbsoluteEnd() {
LinearLayoutManager linearLayoutManager = (LinearLayoutManager) mRecyclerView.getLayoutManager();
if (linearLayoutManager.getOrientation() == LinearLayoutManager.HORIZONTAL) {
return !mRecyclerView.canScrollHorizontally(1);
} else {
return !mRecyclerView.canScrollVertically(1);
}
}
}
And now in your fragment/activity use
CustomVerticalOverScrollDecorator overScrollDecorator =
new CustomVerticalOverScrollDecorator(new CustomRecyclerViewOverScrollDecorAdapter(yourRecyclerView));
Where CustomVerticalOverScrollDecorator smth like this
public class CustomVerticalOverScrollDecorator extends VerticalOverScrollBounceEffectDecorator {
public CustomVerticalOverScrollDecorator(IOverScrollDecoratorAdapter viewAdapter) {
this(viewAdapter, DEFAULT_TOUCH_DRAG_MOVE_RATIO_FWD, DEFAULT_TOUCH_DRAG_MOVE_RATIO_BCK, DEFAULT_DECELERATE_FACTOR);
}
public CustomVerticalOverScrollDecorator(IOverScrollDecoratorAdapter viewAdapter, float touchDragRatioFwd, float touchDragRatioBck, float decelerateFactor) {
super(viewAdapter, touchDragRatioFwd, touchDragRatioBck, decelerateFactor);
// Some setup on the view itself.
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With