【问题标题】:Recyclerview not scrolling all elements of list inside nested scrollviewRecyclerview没有滚动嵌套滚动视图内的所有列表元素
【发布时间】:2019-08-13 06:01:11
【问题描述】:

Recyclerview 不会在嵌套滚动视图中滚动适配器的所有元素。如果我使用没有嵌套滚动视图的 Recyclerview,它可以正常工作。

在搜索了许多解决方案后,将 layout_height 设置为扭曲 recyclerview 和嵌套滚动视图的内容。

这是我的布局

<androidx.coordinatorlayout.widget.CoordinatorLayout               
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"                
 android:layout_height="match_parent"
 xmlns:app="http://schemas.android.com/apk/res-auto">

            <com.google.android.material.appbar.AppBarLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:theme="@style/AppTheme.AppBarOverlay"
              tools:ignore="Missing Constraints">
            <androidx.appcompat.widget.Toolbar
              android:id="@+id/transactionHistoryToolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="@color/groupColor"
              android:elevation="@dimen/_2"
              android:theme="@style/AppTheme.PopupOverlay">
            </androidx.appcompat.widget.Toolbar>
            </com.google.android.material.appbar.AppBarLayout>

           <androidx.core.widget.NestedScrollView
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:isScrollContainer="true"
             android:measureAllChildren="true"
             app:layout_behavior="@string/appbar_scrolling_view_behavior">

           <androidx.constraintlayout.widget.ConstraintLayout
             android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_marginBottom="@dimen/_2">

             <TextView/>
              //other views
                <LinearLayout/>

                 <TextView/>

                    <LinearLayout/>

               <TextView/>

                       <LinearLayout/>

                 <Button
                  />

                  <androidx.recyclerview.widget.RecyclerView
                     android:id="@+id/shipmentList"
                      android:layout_width="match_parent"
                      android:layout_height="0dp"
                     android:layout_marginTop="@dimen/_10"
                     android:layout_marginLeft="@dimen/_7"
                    android:layout_marginRight="@dimen/_7"
                     android:clickable="true"
                     android:visibility="gone"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">             
        </androidx.recyclerview.widget.RecyclerView>
                   <TextView/>
                   </androidx.constraintlayout.widget.ConstraintLayout>          
                  </androidx.core.widget.NestedScrollView>

                  </androidx.coordinatorlayout.widget.CoordinatorLayout>

【问题讨论】:

  • 在您的问题中添加您的 java/kotlin 类文件。
  • 为什么recyclerview的布局高度是0dp?你也禁用了这个recyclerview.setNestedScrollingEnabled(false);
  • recyclerView.setHasFixedSize(true); recyclerView.setNestedScrollingEnabled(false);这两行需要添加到你的类文件中。
  • 这两行都添加到我的类文件@SnehaSarkar
  • 是的,我有@sanjeev

标签: android android-layout android-recyclerview android-nestedscrollview


【解决方案1】:

你也可以设置这条线

ViewCompat.setNestedScrollingEnabled(recyclerView, false); 当我们用 xml 编写时,发送到您的适配器,我有同样的问题,所以我引用了一个链接,我正在与您共享 https://android.jlelse.eu/recyclerview-within-nestedscrollview-scrolling-issue-3180b5ad2542

【讨论】:

    【解决方案2】:

    我找到了解决方案。约束布局的主要问题。用相对布局替换后它工作正常。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-15
      • 1970-01-01
      • 2018-02-22
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多