ScrollView 内的 Recyclerview 滚动不顺畅 [英] Recyclerview inside ScrollView not scrolling smoothly
问题描述
对于我的应用程序,我在 ScrollView
中使用了 RecyclerView
,其中 RecyclerView
的高度基于其使用 这个库.滚动正在工作,但当我滚动 RecyclerView
时,它无法顺利工作.当我滚动 ScrollView
本身时,它正在平滑滚动.
For my app I am using a RecyclerView
inside a ScrollView
where the RecyclerView
has a height based on its content using this library. Scrolling is working but it's not working smoothly when I scroll over the RecyclerView
. When I scroll over the ScrollView
itself it is scrolling smoothly.
我用来定义RecyclerView
的代码:
LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false);
mFriendsListView.setLayoutManager(friendsLayoutManager);
mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null));
ScrollView
中的RecyclerView
:
<android.support.v7.widget.RecyclerView
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:id="@+id/friendsList"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
推荐答案
尝试做:
RecyclerView v = (RecyclerView) findViewById(...);
v.setNestedScrollingEnabled(false);
作为替代方案,您可以使用支持设计库修改您的布局.我猜你目前的布局是这样的:
As an alternative, you can modify your layout using the support design library. I guess your current layout is something like:
<ScrollView >
<LinearLayout >
<View > <!-- upper content -->
<RecyclerView > <!-- with custom layoutmanager -->
</LinearLayout >
</ScrollView >
您可以将其修改为:
<CoordinatorLayout >
<AppBarLayout >
<CollapsingToolbarLayout >
<!-- with your content, and layout_scrollFlags="scroll" -->
</CollapsingToolbarLayout >
</AppBarLayout >
<RecyclerView > <!-- with standard layoutManager -->
</CoordinatorLayout >
然而,这是一条更长的路要走,如果您对自定义线性布局管理器没问题,那么只需在回收站视图上禁用嵌套滚动即可.
However this is a longer road to take, and if you are OK with the custom linear layout manager, then just disable nested scrolling on the recycler view.
支持库的 v 23.2
版本现在在所有默认 LayoutManager
中包含工厂包装内容"功能.我没有测试它,但你可能更喜欢它而不是你正在使用的那个库.
The v 23.2
release of the support libraries now includes a factory "wrap content" feature in all default LayoutManager
s. I didn’t test it, but you should probably prefer it to that library you were using.
<ScrollView >
<LinearLayout >
<View > <!-- upper content -->
<RecyclerView > <!-- with wrap_content -->
</LinearLayout >
</ScrollView >
这篇关于ScrollView 内的 Recyclerview 滚动不顺畅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!