Bounce Effect on RecyclerView

纵饮孤独 提交于 2019-12-20 10:44:35

问题


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?


回答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"/>



回答2:


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.
   }
  }


来源:https://stackoverflow.com/questions/31632542/bounce-effect-on-recyclerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!