Reputation: 3885
I want to have a pagination for the recyclerview but , In my case , the recyclerView is inside a ScrollView. So the onscrollListener not working as expected. So I am planning to find the scroll end for the ScrollView and will fire the next page request.
Is this a good solution or Do somebody have a better idea?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent" android:fillViewport="false">
<LinearLayout android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<FrameLayout android:id="@+id/headerContainer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<android.support.v4.view.ViewPager
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
Upvotes: 1
Views: 1717
Reputation: 465
You can use the following code for intercepting the RecyclerView scrolls and can fine tune your scroll events on basis of that, I hope it help
mList.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() {
float rawX;
int mSlop = ViewConfiguration.get(getActivity()).getScaledTouchSlop();
@Override
public boolean onInterceptTouchEvent(RecyclerView v, MotionEvent event) {
switch (event.getActionMasked()) {
case MotionEvent.ACTION_DOWN:
v.getParent().requestDisallowInterceptTouchEvent(true);
rawX = event.getRawX();
break;
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
v.getParent().requestDisallowInterceptTouchEvent(false);
rawX = 0f;
break;
case MotionEvent.ACTION_MOVE:
if (Math.abs(rawX - event.getRawX()) > mSlop)
v.getParent().requestDisallowInterceptTouchEvent(true);
break;
}
return false;
}
@Override
public void onTouchEvent(RecyclerView rv, MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
});
Upvotes: 1