在一个Fragment布局中实现Android多个RecyclerView(水平和垂直)

4

我希望在一个页面布局中使用多个RecyclerView

我需要以下列表:

方法1:

<ScrollView>
    <ViewPager></ViewPager> <!-- horizontal image slider 10 item -->
    <RecyclerView></RecyclerView> <!-- horizontal -->
    <RecyclerView></RecyclerView> <!-- gridview -->
    <RecyclerView></RecyclerView> <!-- horizontal -->
    <RecyclerView></RecyclerView> <!-- horizontal -->
    <RecyclerView></RecyclerView> <!-- gridview -->
    <RecyclerView></RecyclerView> <!-- horizontal -->
</ScrollView>

方法二:
<Relativelayout>
    <RecyclerView>
        <!-- viewtype for ViewPager horizontal image slider 10 item -->
        <!-- viewtype for horizontal  -->
        <!-- viewtype for gridview -->
        <!-- viewtype for horizontal  -->
        <!-- viewtype for horizontal  -->
        <!-- viewtype for gridview -->
        <!-- viewtype for horizontal  -->
    </RecyclerView>
</Relativelayout>

为了实现这个功能,我找到了两种方法:
  • 第一种方法是使用RecyclerView,并使用ItemViewType
  • 将所有Recycleview添加到一个ScrollView
哪种方法是正确的呢?
每种方法都有问题,我无法找到解决方法。
问题如下:
  • 使用<ScrollView>方法:在向下滚动之前加载所有屏幕外的图像。(但是滚动速度很快,非常流畅)
  • 使用一个Recycleview(多个条目视图类型)非常嵌套,滚动不流畅,速度慢且卡顿。
GooglePlay应用程序中列表的设计是怎样的?(嵌套和平滑)
谢谢您的帮助。

还有一件事,你在ScrollView中使用过vertical LinearLayout吗? - Mayur Raval
@MayurRaval 是的 - frzdno
@cricket_007 你的意思是:一个RecyclerView和7个itemViewType,每个viewType都包含一个RecyclerView? - frzdno
@cricket_007 我已经测试了这个方法,但是在向下滚动时会有毫秒级的延迟:( - frzdno
如果您想使用ScrollView和RecyclerView,那么请使用NestedScrollView来包含多个RecyclerView。 - Android Geek
显示剩余5条评论
2个回答

0

找到的解决方案:

方法 2 更好。使用一个带有 ItemViewType 的 recycleView。 不要在 onBindViewHolder 中设置 setAdapter(),这会导致卡顿。将 setAdapter() 放在 ViewHolder 中,并进行平滑滚动。


如何在这里添加无限滚动? - rupesh

0

请参考以下代码:

      <android.support.v4.widget.NestedScrollView
        android:id="@+id/scrollView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:scrollbars="vertical">
          <LinearLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:orientation="vertical">
            <android.support.v7.widget.RecyclerView
             android:id="@+id/recylerView1"
             android:layout_width="match_parent"
             android:layout_height="wrap_content">
            </android.support.v7.widget.RecyclerView>

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

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

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

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

       <!--You can add as many recycler views you want here--> </LinearLayout>
        </android.support.v4.widget.NestedScrollView>

我已经使用了scrollView方法,但我的问题是:在向下滚动之前加载滚动视图中的所有图像。nestedScrollView解决这个问题吗? - frzdno
请尝试一次。我的问题是它没有为我的情况加载所有的回收视图,它缺少了一些视图。 - Android Geek
你从哪里加载图片? - Android Geek
从网络中加载。我使用Fresco库来加载recyclerView imageView项目。所有图像都在显示屏外加载。我希望只有在滚动时才加载图像 :| - frzdno
渲染期间引发异常:NestedScrollView 只能包含一个直接子元素。 - frzdno
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接