【发布时间】: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