【问题标题】:Android multiple horizontal recycler-view scroll togetherAndroid多个水平回收器-视图一起滚动
【发布时间】:2019-02-01 12:33:50
【问题描述】:

你好,我有一个包含两个像这样的回收器视图的 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>

如何让这个回收器一起滚动?

【问题讨论】:

标签: android android-recyclerview


【解决方案1】:

把这段代码放在Scroll View中,它会自动滚动。 您还可以将多个回收器视图放在线性布局中,它将完美地工作。

<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 这会很有帮助

【讨论】:

  • 这不是他问的——他正在寻找一种方法让他的两个 recyclrView 一起滚动,你只是把它们放在 scrollView 里面(如果我错了,请纠正我)跨度>
  • 我的答案仍然相同,您也可以这样做,我制作的滚动视图水平滚动,您的回收站视图将同时滚动视图。 2,3,4...你想添加多少recyclerview
  • 如何让滚动视图水平滚动?
  • 你能用图片告诉我你想要达到的目标吗@MoayedAlayseh
【解决方案2】:

使用

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(); } } });

将第一个 recyclerview x & y 设置为第二个 recyclerview 以滚动将第一个。

【讨论】:

    猜你喜欢
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-08
    相关资源
    最近更新 更多