RecyclerView内嵌滚动视图滚动,但不像正常的Recyclerview或嵌套滚动视图快速滚动

我在NestedScrollView内使用RecyclerView ,它的工作原理。 但是当我在LinearLayout使用RecyclerView时,它会根据手势以各种速度滚动。 滚动听手势,如果我只滑动了一下,那么它会滚动一点点,而如果我真的很快滑动,那么它滚动真的很快。 现在我的问题是, NestedScrollView里面的NestedScrollView肯定滚动,但快速滚动不起作用。 但是,我滑快或慢, RecyclerViewNestedScrollView只滚动一点点。

我怎样才能使我的NestedScrollViewRecyclerView内滚动视图滚动不同速度?

尝试

 recyclerView.setNestedScrollingEnabled(false); 

默认情况下, setNestedScrollingEnabled只能在API-21之后工作。

你可以使用ViewCompat.setNestedScrollingEnabled(recyclerView, false); 禁用API-21(棒棒糖)之前和之后的嵌套滚动。 链接到文档 。

希望这个帮助!

我正在工作的Android 16,这是不可能使用setNestedSCrollEnabled方法,

我最终做了什么来阻止RecyclerView处理滚动。

像在LinerLayoutManager中,我做了canScrollHorizo​​ntally,canScrollVertically默认返回false。

 myRecyclerView.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false){ @Override public boolean canScrollHorizontally() { return false; } @Override public boolean canScrollVertically() { return false; } }); 

经过几次迭代,我想出了一个解决scheme。

  1. 如果您使用的是RecyclerView,那么:

     recyclerView.setNestedScrollingEnabled(false); 
  2. 如果您在NestedScrollingView中使用LinearLayout,请在正常的ScrollView中使用LinearLayout,然后将其滚动设置为

     scrollView.setNestedScrollingEnabled(false); 

您可以使用ScrollView与覆盖onMeasure方法的ExtendRecyclerView类。 这对我行得通!

 @Override protected void onMeasure(int widthSpec, int heightSpec) { int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthSpec, expandSpec); } 
 recyclerView.setNestedScrollingEnabled(false); 

有时候会很有用。但是这是不可取的,因为它在recylcer视图中禁用视图回收function。

备择scheme:

用Recycler视图试试CollapsiveToolbarLayout。 在collapsiveTollbar布局中放置其他视图。

这是WAI。 NestedScrollView使用Spec“Unspecified”来测量它的孩子。 孩子也可以随心所欲地成长。

这基本上等同于NSV和RV的高度。 所以就房车而言,它认为它是完全显示的。

用你的房车包好你的房车,给你的房车高度。 LL不会将测量规范设置为“未知”,因此RV会在您提供的任何DP的设定高度内正确滚动。

这种方法唯一的缺点是,你不能在你的房车上做一个匹配父母。

你应该像LinearLayout一样在任何布局中包装回收站视图,并将RecyclerView大小设置为常量,如800dp。 这将使滚动过程中的平滑滚动和回收视图仍将回收视图。

 <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="800dp" app:layout_behavior="@string/appbar_scrolling_view_behavior"/> </LinearLayout>