0

In my program, bottom over scroll effect looks bad, so I want to show overscroll effect only at the top.

enter image description here

This is xml file containing the recyclerview.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:clipChildren="false">
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/day_events_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        />
</RelativeLayout>

When I set attribute android:overScrollMode="never", both top and bottom over scroll effects are not showing. Can anyone solve this problem?

Gary Chen
  • 248
  • 2
  • 14

1 Answers1

2

You can use a listener like this:

myRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
        super.onScrolled(recyclerView, dx, dy);

        if (dy > 0) {

            int pos = linearLayoutManager.findLastVisibleItemPosition();
            int numItems = myRecyclerView.getAdapter().getItemCount();

            if (pos >= numItems - 1 ) {
                recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);
            }else{
                 recyclerView.setOverScrollMode(View.OVER_SCROLL_ALWAYS); 
              }
        }
    }
});
Francesco Bocci
  • 827
  • 8
  • 19
  • Thanks for your answer, but I just want to block bottom over scroll, not detecting. – Gary Chen Oct 07 '20 at 12:51
  • Detecting bottom overscroll, you can block it using `recyclerView.setOverScrollMode(View.OVER_SCROLL_NEVER);` and re-enable again when you are not in the bottom – Francesco Bocci Oct 07 '20 at 12:54
  • Ah, okay. Then can you share the full code? Currently, your answer is not explained enough to be accepted. – Gary Chen Oct 07 '20 at 12:56