如何解决在垂直RecyclerView内的水平RecyclerView上垂直滚动时,AppBarLayout不会折叠/展开
当垂直RecyclerView具有水平RecyclerView时,如果用户开始用手指在水平RecyclerView上垂直滚动,则AppBarLayout完全不会移动。如果手指在其他列表项上,则AppBarLayout确实会更改其状态。
Collapsibletoolbar
的代码摘自this文章。
AppBarLayout中的CollapsingToolbarLayout
仍然存在问题。
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="76dp"
android:theme="@style/AppTheme.AppBarOverlay.Light">
<com.example.notcollapsingappbar.Collapsibletoolbar
android:id="@+id/motion_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="@dimen/actionBarSize"
app:layoutDescription="@xml/scene_header"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:popupTheme="@style/AppTheme.PopupOverlay" />
<TextView
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="start|center_vertical"
android:text="Large title"
android:textColor="@android:color/white"
android:textSize="30sp"
app:autoSizeTextType="uniform" />
</com.example.notcollapsingappbar.Collapsibletoolbar>
</com.google.android.material.appbar.AppBarLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:paddingBottom="16dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
解决方法
您可以将此行添加到水平RecyclerView
。
android:nestedScrollingEnabled="false"
或以编程方式:
recyclerView.setNestedScrollingEnabled(false);
,
@potados的答案解决了这个问题。但是没有解释它为什么起作用。
我在issue的GitHub页面上创建了一个material components android,并提出了相同的问题。我想在这里发布我收到的答案。
尝试将Horizontal RecyclerView的nestedScrollEnable设置为false
如果启用NestedScrollingChild作为子视图,则NestedScrollingParent作为父布局将不会拦截滚动事件
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。