gpt4 book ai didi

android - ScrollView 内的 Recyclerview 滚动不顺畅

转载 作者:IT老高 更新时间:2023-10-28 12:55:10 25 4
gpt4 key购买 nike

对于我的应用程序,我在 ScrollView 内使用 RecyclerView,其中 RecyclerView 的高度基于使用 this library 的内容.滚动正常,但当我滚动 RecyclerView 时,它运行不顺畅。当我滚动 ScrollView 本身时,它正在平滑滚动。

我用来定义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);

作为替代方案,您可以使用支持设计库修改布局。我猜你当前的布局是这样的:

<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 >

然而,这是一条更长的路,如果您对自定义线性布局管理器没问题,那么只需禁用回收器 View 上的嵌套滚动即可。

编辑(2016 年 4 月 3 日)

支持库的 v 23.2 版本现在在所有默认 LayoutManager 中包含工厂“包装内容”功能。我没有测试它,但你可能应该更喜欢它而不是你正在使用的那个库。

<ScrollView >
<LinearLayout >

<View > <!-- upper content -->
<RecyclerView > <!-- with wrap_content -->

</LinearLayout >
</ScrollView >

关于android - ScrollView 内的 Recyclerview 滚动不顺畅,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33143485/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com