1

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 ?

shashank chandak
  • 544
  • 5
  • 13
Moayed Alayseh
  • 188
  • 3
  • 14
  • Can you explain a bit more – Vignesh Feb 01 '19 at 12:48
  • i have two horizontal recyclerview , i need to make this recyclers scroll horizontally together – Moayed Alayseh Feb 01 '19 at 12:53
  • check this [link](https://stackoverflow.com/questions/40012389/i-want-to-scroll-multiple-recyclerview-at-a-time-how-to-achieve-that) – Vignesh Feb 01 '19 at 12:56
  • Does this answer your question? [Sync scrolling of multiple RecyclerViews](https://stackoverflow.com/questions/30702726/sync-scrolling-of-multiple-recyclerviews) – Waqleh Feb 04 '20 at 12:45

2 Answers2

1

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

007
  • 516
  • 1
  • 5
  • 17
  • This is not what he asked - he is looking for a way to make both of his recyclrView to be scrolled together , you just went and put them inside scrollView(correct me if i am wrong) – Tamir Abutbul Feb 01 '19 at 12:46
  • still my answer is same you can also do that my making scrollview which scroll horizontally and both your recycler view will scroll view at the same time. 2,3,4... as many recyclerview you want to add – 007 Feb 01 '19 at 12:49
  • how to make scroll view scroll horizontally ? – Moayed Alayseh Feb 01 '19 at 12:52
  • can you show me with image what you want to achieve @MoayedAlayseh – 007 Feb 01 '19 at 13:13
0

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.

Chintan
  • 394
  • 2
  • 7