Android ViewPager滚动布局行为不使用工具栏

Android ViewPager滚动布局行为不使用工具栏,android,android-layout,android-fragments,android-viewpager,android-toolbar,Android,Android Layout,Android Fragments,Android Viewpager,Android Toolbar,我正在处理一些与ViewPager、AppBarLayout和工具栏相关的奇怪问题 在我的布局中,我有一个标准的材质设计设置,例如: <android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="ht

我正在处理一些与
ViewPager
AppBarLayout
工具栏
相关的奇怪问题

在我的布局中,我有一个标准的材质设计设置,例如:

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="...">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.v7.widget.Toolbar
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/grey_900"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:layout_scrollFlags="scroll|enterAlways" />

        <android.support.design.widget.TabLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill"
            app:tabBackground="@color/grey_900"
            app:tabIndicatorColor="@color/white_1000"
            app:tabIndicatorHeight="4dp" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.FloatingActionButton
        ...
        app:layout_behavior="com.inkstinctapp.inkstinct.FabBehavior" />

</android.support.design.widget.CoordinatorLayout>
除非我从我的viewpager中删除
appbar\u scrolling\u view\u行为
,否则它们似乎都不起作用,因为viewpager位于AppBarLayout下


我做错了什么?任何帮助都将不胜感激

尝试将工具栏包装在折叠工具栏布局中,如下所示

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    >

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_scrollFlags="scroll|exitUntilCollapsed"
        >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            />

    </android.support.design.widget.CollapsingToolbarLayout>

    <android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabBackground="@color/ezy_green"
        app:tabGravity="fill"
        app:tabIndicatorColor="@color/gray_background"
        app:tabIndicatorHeight="4dp"
        app:tabMode="fixed"/>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

别忘了将scrollview行为添加到回收器视图中,并设置其余属性以满足您的需要

您可以尝试

app:layout_behavior="@string/appbar_scrolling_view_behavior"
例如代码

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainScreen">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <!--
     <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    -->

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        style="@style/AppTabLayout"
        app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<!--<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/fragment_container">-->

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<!--</FrameLayout>-->


以下是您想要实现的行为的广泛布局实现

<CoordinatorLayout>
 <AppbarLayout/>
 <Viewpager 
 .
 .
 app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
 <FloatingActionButton/>
</CoordinatorLayout>
此外,您还可以试验这些标志及其值。但是请记住,
AppbarLayout
是一个具有超级能力的垂直
LinearLayout
。因此,请相应地放置您的视图。

您应该使用坐标布局作为父布局,以便在您的查看页面中访问(app:layout\u behavior)。

尝试在片段布局中添加
app:layout\u behavior=“@string/appbar\u scrolling\u view\u behavior”
中的
您使用哪个版本的appcompat?23.2在AppBarLayout+SwipeRefreshLayout+SwipeRefreshLayout@Rehan没有,工具栏仍然不可滚动。。多谢各位way@marco我在23.4.0上,仍然有问题,可能这里有更多信息。使用23.1.1,所有功能都运行良好。但我不知道这是否是真正的问题这似乎是合法的,不幸的是,我现在无法测试,因为从那时起应用程序的设计已经改变了,我以后一定会尝试。也谢谢你的博客链接,这将是非常重要的useful@Matteo自从这些组件首次发布以来,我一直在对它们进行实验。别担心,它肯定会有用的。现在,QuickReturn行为主要取决于Viewpager中布局的复杂性。欢迎光临!
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/mainScreen">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

    <!--
     <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:layout_scrollFlags="scroll|enterAlways"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    -->

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        style="@style/AppTabLayout"
        app:tabGravity="fill"/>
</android.support.design.widget.AppBarLayout>

<!--<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/fragment_container">-->

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

<!--</FrameLayout>-->
<CoordinatorLayout>
 <AppbarLayout/>
 <Viewpager 
 .
 .
 app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
 <FloatingActionButton/>
</CoordinatorLayout>
<AppBarLayout>
    <CollapsingToolbarLayout
        app:layout_scrollFlags="scroll|snap"
        />

    <Toolbar
        app:layout_scrollFlags="scroll|snap"
        />

    <LinearLayout
        android:id="+id/title_container"
        app:layout_scrollFlags="scroll|enterAlways"
        />

    <TabLayout /> <!-- no flags -->
</AppBarLayout>