/ / Recyclerview onscrolllistener nie działa, gdy RecyclerView wewnątrz ScrollView - android, android-recyclinglerview, android-scrollview

Recyclerview onscrolllistener nie działa, gdy RecyclerView wewnątrz ScrollView - android, android-recyclerview, android-scrollview

Chcę mieć stronicowanie dla widoku recykleraale w moim przypadku recyklerView znajduje się w ScrollView. Tak więc onscrollListener nie działa zgodnie z oczekiwaniami. Planuję więc znaleźć koniec przewijania dla ScrollView i uruchomić następną stronę.

Czy to dobre rozwiązanie, czy ktoś ma lepszy pomysł?

    <?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>

Odpowiedzi:

0 dla odpowiedzi № 1

Możesz użyć następującego kodu do przechwytywania zwojów RecyclerView i na tej podstawie możesz dostroić zdarzenia przewijania, mam nadzieję, że to pomoże

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) {

}
});