简体   繁体   English

Android多个水平回收站视图一起滚动

[英]Android multiple horizontal recycler-view scroll together

hello i have android app that contain two recycler-view like this 你好,我有包含两个这样的回收站视图的android应用程序

 <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 ? 如何使这些回收商一起滚动?

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 https://stackoverflow.com/a/43645502/7522720这将是有帮助的

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. 将第一个recyclerview xy设置为第二个recyclerview,以滚动第一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM