[英]Recyclerview onscrolllistener not working when RecyclerView inside a ScrollView
I want to have a pagination for the recyclerview but , In my case , the recyclerView is inside a ScrollView. 我想对recyclerview进行分页,但是,就我而言,recyclerView在ScrollView内。 So the onscrollListener not working as expected. 因此,onscrollListener无法正常工作。 So I am planning to find the scroll end for the ScrollView and will fire the next page request. 因此,我计划为ScrollView找到滚动端,并将触发下一个页面请求。
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>
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 您可以使用以下代码来拦截RecyclerView滚动,并以此为基础微调滚动事件,希望对您有所帮助
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) {
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.