RecyclerView上的反弹效果

pro*_*m85 8 android bounce android-recyclerview

我想在a上使用反弹效果 RecyclerView.每当我过度滚动内容时都会产生反弹效果......

是否存在库或示例?

Cha*_*hai 13

我也找不到任何支持RecyclerView反弹效果的库.最终我自己最终实现了一个新的库.看看我的图书馆overscroll-bouncy-android..它目前支持使用LinearLayoutManager的RecyclerView.我也在使用ListView和ScrollView.

要使用我的库:

步骤1:

dependencies {
    compile 'com.chauthai.overscroll:overscroll-bouncy:0.1.0'
}
Run Code Online (Sandbox Code Playgroud)

第2步:

<com.chauthai.overscroll.RecyclerViewBouncy
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>
Run Code Online (Sandbox Code Playgroud)

  • 我在 SwipeRefreshLayout 中有 RecyclerViewBouncy,它看起来像 RecyclerViewBouncy 吞下下拉事件并且没有触发刷新 (2认同)

Ash*_*agi 5

这可以通过动态动画轻松完成,无需使用任何第三方库

在这里写了一篇关于这个的文章。

另一个优点是它可以与任何类型的布局管理器一起使用,并且由于我们使用的是基于物理的动态动画,因此动画感觉更自然


War*_*an- 4

您可以使用这个库https://github.com/EverythingMe/overscroll-decor 因此,您需要像这样创建自己的 ScrollDecorAdapter

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);
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

现在在您的片段/活动中使用

 CustomVerticalOverScrollDecorator overScrollDecorator =
            new CustomVerticalOverScrollDecorator(new CustomRecyclerViewOverScrollDecorAdapter(yourRecyclerView));
Run Code Online (Sandbox Code Playgroud)

其中 CustomVerticalOverScrollDecorator 像这样

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.
   }
  }
Run Code Online (Sandbox Code Playgroud)