android - 在垂直 RecyclerView 内的水平 RecyclerView 上垂直滚动时,AppBarLayout 不会折叠/展开
问题描述
当垂直 RecyclerView 具有水平 RecyclerView 并且如果用户开始用手指在水平 RecyclerView 上垂直滚动,则 AppBarLayout 根本不会移动。如果手指在其他列表项上,则 AppBarLayout 会更改其状态。
代码CollapsibleToolbar
取自这篇文章。
CollapsingToolbarLayout
AppBarLayout 内部的问题仍然存在。
我的代码有问题还是库错误?
<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>
解决方案
@potados 的回答解决了这个问题。但没有解释为什么它有效。
我在材料组件 android的GitHub 页面上用同样的问题创建了一个问题。我想发布我在那里收到的答案。
尝试将 Horizontal RecyclerView 的 nestedScrollEnable 设置为 false
如果启用了作为子View的NestedScrollingChild,作为父布局的NestedScrollingParent将不会拦截滚动事件
推荐阅读
- vba - 自动保存 Outlook 附件 VBA
- xamarin - 如何根据 XML 页面动态构建内容页面以获取不同的用户输入
- python - Python MySQL-Connector 需要一分钟以上才能打开连接
- jquery - 我需要将贷款计算器从滑块更改为输入文本框
- c++ - 使用 QMetaType 访问类静态成员
- javascript - 在 window.onload 上触发 JS 事件并直接从输入字段中选择处理后的 html 参数
- ruby-on-rails - 是否可以通过为集合传递局部变量来呈现部分?
- linux - 使用 awk 过滤掉无法识别的字段
- javascript - 在ionic4中使用addjavascriptinterface for webview来使用本机代码
- python - pandas- 为列中每个唯一字符串/组的新计算行