Detecting overscroll in NestedScrollView

953 Views Asked by At

I want a vertical overscroll in a NestedScrollView to trigger one of my methods, which displays a ContentLoadingProgressBar while retrieving data from another device.

The SwipeRefreshLayout widget does not look good with my app and there does not seem to be any way of customizing the actual animation (see this question).

I have tried subclassing NestedScrollView and overriding onOverScrolled:

@Override
public void onOverScrolled(int scrollX, int scrollY, boolean clampedX, boolean clampedY) {
  super.onOverScrolled(scrollX, scrollY, clampedX, clampedY);

  if (clampedY && scrollY == 0) {
    Log.d("MyNestedScrollView", "Top overscroll detected");
    // myTopOverScrollMethod();
  } else if (clampedY && scrollY > 0) {
    Log.d("MyNestedScrollView", "Bottom overscroll detected");
    // myBottomOverScrollMethod();
  }
}

However, my logging messages get printed 5-10 times per overscroll since the gesture is not instantaneous and takes a while to complete.

I am looking for a way of recognizing an overscroll gesture in order to display my ContentLoadingProgressBar to indicate that data is being refreshed.

Is there a nice, clean way of doing this? Or do I need to deal with the fact that onOverScrolled is called multiple times?

0

There are 0 best solutions below