【问题标题】:Nested scroll View not scrolling smoothly with recyclerview android嵌套滚动视图无法使用recyclerview android平滑滚动
【发布时间】:2016-12-14 03:36:12
【问题描述】:

我正在使用 Nested Scrollview 来包装 recyclerview 和其他按钮。它工作得很好,但我注意到当我滚动它时它并不流畅。请指导如何使滚动平滑。

 <android.support.v4.widget.NestedScrollView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/scrollView"
                        android:fillViewport="true">
                        <LinearLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:orientation="vertical">
                            <LinearLayout
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content">
                                <Button
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_filter"
                                    android:text="Filter"
                                    android:id="@+id/btn_filter"
                                    android:layout_margin="0dp"
                                    android:layout_weight="1"
                                    />
                                <Button
                                    android:layout_width="match_parent"
                                    android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_action_sortbyt"
                                    android:layout_margin="0dp"
                                    android:text="Sort By"
                                    android:id="@+id/btn_sortby"
                                    android:layout_weight="1"/>
                            </LinearLayout>
                            <android.support.v7.widget.RecyclerView
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:id="@+id/lastest_product_list"
                                android:nestedScrollingEnabled="false"
                                android:isScrollContainer="false">
                            </android.support.v7.widget.RecyclerView>
                        </LinearLayout>
                    </android.support.v4.widget.NestedScrollView>

【问题讨论】:

    标签: android


    【解决方案1】:

    根据 Android 文档,android:nestedScrollingEnabled="false" 有效,但仅适用于 Android API level &gt;= 21。

    如果您还想支持 API 21 以下的设备,请使用以下命令:

    ViewCompat.setNestedScrollingEnabled(recyclerView, false);
    

    【讨论】:

      【解决方案2】:

      试试下面的代码:

       RecyclerView recycleView = (RecyclerView) findViewById(R.id.lastest_product_list);
          recycleView.setNestedScrollingEnabled(false);
      

      你可以修改你的布局

      <ScrollView>
           <LinearLayout> 
               <android.support.v7.widget.RecyclerView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/lastest_product_list"
                    android:nestedScrollingEnabled="false"
                    android:isScrollContainer="false">
              </android.support.v7.widget.RecyclerView>
          </LinearLayout>
      

      在此处查看链接:Recyclerview inside ScrollView not scrolling smoothly

      【讨论】:

      • recycleView.setNestedScrollingEnabled(false);为我工作,他 xml 没有
      【解决方案3】:

      为了平滑滚动,您可以更改您在编码中为回收站视图设置的布局管理器。希望对你有帮助。

        RecyclerView.LayoutManager layoutManager = new  LinearLayoutManager(getActivity()) {
              @Override
              public boolean canScrollVertically() {
                  return false;
              }
          };
          recyclerView.setLayoutManager(layoutManager);
      

      【讨论】:

      • 完美!你拯救了我的一天。
      猜你喜欢
      • 2016-09-15
      • 1970-01-01
      • 2017-01-16
      • 1970-01-01
      • 2018-07-13
      • 2016-01-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多