如何解决展开时禁用自动滚动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开始滚动。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。