In my implementation of this feature, (the over-scroll is working on both top and bottom), I have my layout like this:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<...<custom view>...SwipeRefreshWrapper
android:id="@+id/swiperefresh_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RecyclerView
android:id="@+id/video_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<include layout="@layout/include_video_list_empty_view"/>
<include layout="@layout/include_watchlist_empty_view"/>
</FrameLayout>
<SwipeRefreshWrapper>
And my SwipeRefreshWrapper implementation is as follows:
/**
* This Class ensures that a SwipeRefreshLayout will only refresh if the
* list it wraps cannot scroll up anymore, (that it is at the top). Otherwise
* when the user attempts to scroll up from the middle of the list, the refresh
* will trigger. This is necessary for custom List implementations, (or
* RecyclerViews), only.
*/
public class SwipeRefreshWrapper extends SwipeRefreshLayout {
private ScrollResolver mScrollResolver;
public SwipeRefreshWrapper(Context context) {
super(context);
}
public SwipeRefreshWrapper(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setScrollResolver(ScrollResolver scrollResolver) {
mScrollResolver = scrollResolver;
}
@Override
public boolean canChildScrollUp() {
if(mScrollResolver != null){
return mScrollResolver.canScrollUp();
} else {
return super.canChildScrollUp();
}
}
public static interface ScrollResolver{
public boolean canScrollUp();
}
}
Then in my Fragment I setup the SwipeRefreshLayout:
/**
* Initializes PullToRefresh handler
*/
private void initPullToRefresh() {
mSwipeRefreshLayout = (SwipeRefreshWrapper) mView.findViewById(R.id.swiperefresh_layout);
mSwipeRefreshLayout.setColorSchemeResources(R.color.colorPrimary, R.color.colorAccent);
mSwipeRefreshLayout.setScrollResolver(new SwipeRefreshWrapper.ScrollResolver() {
@Override
public boolean canScrollUp() {
return mVideoRecycler.canScrollVertically(-1);
}
});
mSwipeRefreshLayout.setOnRefreshListener(...)
}