How to scroll recyclerview based on another one

1k views Asked by At

I have two recycleView in the same layout and same SwipeRefresher one for normal result and another for VIP it's worked as well, but the VIP recycle come above the result recycle, and that gives me a wired result.

The screen show VIP while scrolling in the normal result.

How I can make two recycle with one scroll behavior?

My layout looks like this:-

 <android.support.v4.widget.SwipeRefreshLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/swipeRefreshLayout"
    >
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
    <android.support.v7.widget.RecyclerView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/vipRecycleView"/>
    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/resultRecycleView"
        >

    </android.support.v7.widget.RecyclerView>
    </LinearLayout>

</android.support.v4.widget.SwipeRefreshLayout>

The following image demonstrates my current statue.

enter image description here

2

There are 2 answers

1
SiSa On

Use NestedScrollView and put both RecyclerView's inside it

<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/vipRecycleView"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />

            <android.support.v7.widget.RecyclerView
                android:id="@+id/resultRecycleView"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            </android.support.v7.widget.RecyclerView>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
</android.support.v4.widget.SwipeRefreshLayout>
1
Elinor On

Try

recyclerView.setNestedScrollingEnabled(true)

Main xml

 <android.support.v4.widget.SwipeRefreshLayout 
 xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" 
 android:layout_width="match_parent"
 android:layout_height="match_parent">

 <android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

 </android.support.v4.widget.SwipeRefreshLayout>

recycler item

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

</LinearLayout>