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.
我用来定义<$的代码c $ c> RecyclerView :
LinearLayoutManager friendsLayoutManager = new LinearLayoutManager(getActivity().getApplicationContext(), android.support.v7.widget.LinearLayoutManager.VERTICAL, false);
mFriendsListView.setLayoutManager(friendsLayoutManager);
mFriendsListView.addItemDecoration(new DividerItemDecoration(getActivity().getApplicationContext(), null));
<$ c $中的 RecyclerView
c> ScrollView :
The RecyclerView
in the ScrollView
:
<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.
code> 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屋!