RecyclerView上的反弹效果

问题描述 投票:8回答:2

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

是否存在库或示例?

android android-recyclerview bounce
2个回答
12
投票

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

要使用我的库:

步骤1:

dependencies {
    compile 'com.chauthai.overscroll:overscroll-bouncy:0.1.0'
}

第2步:

<com.chauthai.overscroll.RecyclerViewBouncy
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

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);
    }
  }
}

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

 CustomVerticalOverScrollDecorator overScrollDecorator =
            new CustomVerticalOverScrollDecorator(new CustomRecyclerViewOverScrollDecorAdapter(yourRecyclerView));

自定义垂直OverScroll Decorator就像这样

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.
   }
  }
© www.soinside.com 2019 - 2024. All rights reserved.