7

What is this blue shadow called which apears when the view is pulled after it ends? is there a listener triggered when this appears or goes?

enter image description here

I have implemented https://github.com/maurycyw/StaggeredGridView and I want to load more items when this viewgroup is overscrolled.

Rishabh Srivastava
  • 3,683
  • 2
  • 30
  • 58

2 Answers2

6

It is called as Overscroller.Listview has built-in support for overscrolling. Check out setOverscrollMode and related methods setOverscrollHeader and setOverscrollFooter. ListView makes use of the overscroll header/footer by overriding AbsListView.onOverscrolled; if you want different behavior, you can implement it by overriding it yourself.

williamj949
  • 11,166
  • 8
  • 37
  • 51
3

unfortunately there's no ready library or functionality to achieve that. But there're good open library that you can adapt.

My suggestion is to check SwipeRefreshLayout, it's on the Android support library.

This ViewGroup support a swipe from the top to give a callback, you probably can adapt it to implement a bottom swipe.

docs: https://developer.android.com/reference/android/support/v4/widget/SwipeRefreshLayout.html

source code: https://android.googlesource.com/platform/frameworks/support/+/refs/heads/master/v4/java/android/support/v4/widget/SwipeRefreshLayout.java

edit: alternatively, to implement a load more function with scroll listener is relatively easy, it's just a simple OnScrollListener with the following code:

private long lastRequestTime = 0;
public void onScroll (AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount){
      if (((firstVisibleItem+visibleItemCount) > totalItemCount - 4) &&
         (lastRequestTime + 1000 < System.currentTimeMillis())) {
         lastRequestTime = System.currentTimeMillis();
         // load more ...
      }
}
Budius
  • 39,391
  • 16
  • 102
  • 144