Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bounce Effect on RecyclerView

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?

like image 668
prom85 Avatar asked Jul 26 '15 00:07

prom85


4 Answers

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);
like image 122
Valkriaine Wayne Wang Avatar answered Sep 18 '22 08:09

Valkriaine Wayne Wang


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"/>
like image 15
Chau Thai Avatar answered Nov 11 '22 08:11

Chau Thai


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.

like image 6
Ashu Tyagi Avatar answered Nov 11 '22 07:11

Ashu Tyagi


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.
   }
  }
like image 4
Waran- Avatar answered Nov 11 '22 08:11

Waran-