我有一个基本的布局设置:DrawerLayout,它由活动的主布局和导航视图的布局组成。主布局有一个 CoordinatorLayout 和实现折叠工具栏功能所需的所有布局,以及一个 ViewPager,我稍后在代码中用片段填充它。Fragment 的布局主要由 RecyclerView 和其他次要视图组成。
问题如下:每当我向下滚动两个选项卡中的任何一个并滑动到新选项卡并返回到原始选项卡时,RecyclerView 都会收到 onScrolled 回调(它不应该收到,因为我还没有滚动RV 本身,但 ViewPager)具有负 deltaY 参数(这意味着方向向上),这会导致顶部的下一个项目变得可见。
一些注意事项:
仪表板_activity_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.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:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:elevation="@dimen/toolbar_shadow_height">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:paddingTop="@dimen/toolbar_padding_top"
app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
app:titleTextAppearance="@style/TitleTextView"
tools:background="@color/colorPrimary"/>
<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_activity_content_tab_layout_height"
app:tabMode="fixed"
app:tabGravity="fill"
tools:background="@color/colorPrimary"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:background="@color/colorPrimaryDark"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/actionButtonFab"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud)