如何在scrollview中滚动RecyclerView

时间:2017-07-03 06:16:31

标签: android xml android-recyclerview scrollview

enter image description here

如何在scrollview中滚动所有上面的RecyclerView

我必须在scrollview show中实现RecyclerView,如下面的代码,但不能滚动RecyclerView。

请给出答案

            <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/horizontalScrollView"
            android:layout_marginTop="10dp">

          <RelativeLayout...

                        <android.support.v7.widget.RecyclerView
                            android:id="@+id/rvpouch"
                            android:layout_width="match_parent"
                            android:layout_height="match_parent"
                            android:nestedScrollingEnabled="false"
                            android:layout_below="@+id/textView3">


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

                    </RelativeLayout>

        </ScrollView>

3 个答案:

答案 0 :(得分:4)

请勿在{{1​​}}内使用RecyclerView。使用ScrollView代替NestedScrollView

  

ScrollView就像NestedScrollView一样,但它支持表演   作为新旧的嵌套滚动父级和子级   Android版本。默认情况下启用嵌套滚动。

例如:

ScrollView

使用属性<android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:descendantFocusability="blocksDescendants"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView_one" android:layout_width="match_parent" android:layout_height="wrap_content" android:nestedScrollingEnabled="false"> </android.support.v7.widget.RecyclerView> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView_two" android:layout_width="match_parent" android:layout_height="wrap_content" android:nestedScrollingEnabled="false"> </android.support.v7.widget.RecyclerView> <android.support.v7.widget.RecyclerView android:id="@+id/recyclerView_three" android:layout_width="match_parent" android:layout_height="wrap_content" android:nestedScrollingEnabled="false"> </android.support.v7.widget.RecyclerView> </LinearLayout> </android.support.v4.widget.NestedScrollView> 进行平滑滚动。

答案 1 :(得分:1)

使用NestedScrollView而不是滚动视图并设置

recyclerView.setNestedScrollingEnabled(false);

答案 2 :(得分:-1)

以下代码段将帮助您使用ScrollView的{​​{1}}实现滚动

RecyclerView

希望有所帮助

相关问题