[英]how to scroll RecyclerView in scrollview
如何在滚动视图中滚动 RecyclerView 上方的所有内容
我必须在滚动视图中实现 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>
不要在ScrollView
使用RecyclerView
。 使用NestedScrollView
而不是ScrollView
。
NestedScrollView
就像ScrollView
,但它支持在新旧版本的 Android 上同时充当嵌套滚动父项和子项。 默认情况下启用嵌套滚动。
例如:
<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>
使用属性android:nestedScrollingEnabled="false"
平滑滚动。
使用 NestedScrollView 而不是滚动视图并设置
recyclerView.setNestedScrollingEnabled(false);
以下代码片段将帮助您使用RecyclerView
ScrollView
实现滚动
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarSize="3dp"
android:scrollbarThumbVertical="@drawable/scrollbar_black">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:id="@+id/rlFiltersSearchEvent"
android:layout_width="match_parent"
android:layout_height="250dp"
android:background="@drawable/action_bar_gradient">
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/rvListOfEventsMain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/fab_margin"
android:layout_below="@+id/rlFiltersSearchEvent"
android:nestedScrollingEnabled="false"
android:scrollbars="none" />
</RelativeLayout>
</ScrollView>
希望它有帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.