Moayed Alayseh
Moayed Alayseh

Reputation: 188

Android multiple horizontal recycler-view scroll together

hello i have android app that contain two recycler-view like this

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

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

            android:layout_height="wrap_content" />

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

how to make this recyclers scroll together ?

Upvotes: 1

Views: 2108

Answers (2)

Chintan
Chintan

Reputation: 414

Using

recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() { @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); if (isLastItemDisplaying(recyclerView)) { //Calling the method getdata again getData(); } } });

Set first recyclerview x & y to second recyclerview to scroll will first one.

Upvotes: 0

007
007

Reputation: 526

put this code inside Scroll View then it will automatically scroll. You can also put multiple recycler view inside linear layout and it will work perfectly.

<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/hsv"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

        <LinearLayout
            android:id="@+id/innerLay"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">

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

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

        </LinearLayout>
</android.support.v4.widget.NestedScrollView>

https://stackoverflow.com/a/43645502/7522720 this will be helpfull

Upvotes: 1

Related Questions