Try this if nothing works for you then wrap your recycler view in a scroll view and then check if scroll view has reached its bottom:
In your xml file:
<ScrollView
android:id="@+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</RelativeLayout>
</ScrollView>
In your class file:
private ScrollView mScrollView;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
initScrollView();
...
}
private void initScrollView() {
mScrollView = (ScrollView) mView.findViewById(R.id.scroll_view);
mScrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
@Override
public void onScrollChanged() {
if (mScrollView != null) {
if (mScrollView.getChildAt(0).getBottom() <= (mScrollView.getHeight() + mScrollView.getScrollY())) {
// Scroll view is at bottom
// If not loading then start load more
} else {
// Scroll view is not at bottom
}
}
}
});
}
Remember to set nested scrolling of recycler view to false for smooth scrolling in your class file:
mRecyclerView.setNestedScrollingEnabled(false);
If you want to start loading next page just before it reaches the bottomm, then just subtract an integer from mScrollView.getChildAt(0).getBottom()
For example 1000 is subtracted here:
if (mScrollView.getChildAt(0).getBottom() - 1000 <= (mScrollView.getHeight() + mScrollView.getScrollY())) {
// Scroll view is at bottom
// If not loading then start load more
} else {
// Scroll view is not at bottom
}
Use a greater integer to start loading much before the scroll reaches bottom.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…