Android 项目装饰不';不能在嵌套的滚动视图中工作
我已经实现了带有粘性标题的RecyclerView,我是通过ItemDecoration实现的。 在独立回收器视图的情况下,它可以按预期工作Android 项目装饰不';不能在嵌套的滚动视图中工作,android,android-recyclerview,item-decoration,Android,Android Recyclerview,Item Decoration,我已经实现了带有粘性标题的RecyclerView,我是通过ItemDecoration实现的。 在独立回收器视图的情况下,它可以按预期工作 <LinearLayout ...> <androidx.recyclerview.widget.RecyclerView .../> <androidx.recyclerview.widget.RecyclerView ... /> // ItemDecoration is supposed to be
<LinearLayout ...>
<androidx.recyclerview.widget.RecyclerView .../>
<androidx.recyclerview.widget.RecyclerView ... /> // ItemDecoration is supposed to be here and it works excellent
</LinearLayout>
头饰是从那里复制来的
您是否应该使用
addDecoration(ItemDecoration装饰)
方法将ItemDecoration
添加到RecyclerView
中。在第一个描述的案例中,它工作得很好。即使它实际上不应该在那里,ItemDecoration对第一个RecyclerView有效吗?您试过了吗?能否提供更多详细信息,如视图和视图组的属性?我本想尝试复制这个问题,但如果没有更多的上下文信息,就很难解决这个问题。首先,RecyclerView有一个水平滚动,所以ItemDecoration无法使用它。但如果将第二个RecyclerView移到顶部,它也不会起作用。另外,如果删除NestedScrollView,它可以按预期工作我已经在我的主要问题中添加了更多详细信息,您是否可以澄清一件事,即“ItemDecoration不工作”您的意思是装饰标题不呈现,还是它确实呈现,但没有按要求滚动。ItemDecoration不呈现。实际上,奥德拉沃夫的甚至都不叫
<androidx.core.widget.NestedScrollView ...>
<LinearLayout ...>
<androidx.recyclerview.widget.RecyclerView .../>
<androidx.recyclerview.widget.RecyclerView ... /> // It doesn't work here
</LinearLayout>
</androidx.core.widget.NestedScrollView ...>
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.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:fillViewport="true"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black_background_color"
android:focusableInTouchMode="true"
android:orientation="vertical">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/menuNewsList"
android:layout_width="match_parent"
android:layout_height="170dp" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/listMenu"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
listMenu.apply {
adapter = dishAdapter
isNestedScrollingEnabled = false
}
listMenu.addItemDecoration(HeaderItemDecoration(listMenu, isHeader = isHeader()))