android - 禁用扩展时自动滚动 AppBarLayout
问题描述
如果用户向下滚动列表一点点,我有一个 AppBarLayout 会展开,如果用户不再滚动,它会在 2 秒后恢复。然而,令人讨厌的是 AppBarLayout 也在滚动 RecyclerView 以获取 AppBarLayout 的高度。这样,它将列表保持在用户在列表中停止的相同位置,因此列表不会移动,但是,视口会移动,如果可能的话,我想禁用它。
它起作用的唯一方法是当我将 ViewPager(稍后在包含 RecyclerView 的 Fragment 中)放在 AppBarLayout 上方并移除时app:layout_behavior
。
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/divider_logo">
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/app_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
app:elevation="0dp"
app:layout_behavior="com.my.app.sava.main.AppBarLayoutBehavior">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="scroll|enterAlways">
<View
android:id="@+id/tv_location_bg"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/colorPrimaryLight"
app:layout_constraintBottom_toBottomOf="@id/tv_location"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_location" />
.
.
.
然而,当想要滚动时会有延迟,因为 AppBarLayout 首先滚动而不移动列表,然后 RecyclerView 开始滚动。
解决方案
推荐阅读
- sql - ORA-00933: SQL 命令未以 pyspark 表达式正确结束
- python-3.x - 在 GCP App Engine 标准环境上安装 cmake 的解决方法
- xamarin - 访问 CollectionView 中的对象
- shortcode - 数据内容中的 11 个简码未呈现
- java - Kibana 启用了您当前浏览器不符合的严格安全要求
- python - Python - 在 Windows 上获取实际文件名(使用正确的大小写)?
- elasticsearch - Jmeter对ElasticSearch的http请求中的三引号
- python - 进行价值选择的最快方法?
- python-3.x - python中sorted()函数背后的逻辑
- flutter - 在 Flutter 中使用 Dio 包下载多个文件