1

在我的应用程序中,我想为带有标签的工具栏实现快速返回模式,例如 Google Play 应用程序中的选项卡。

这是我的活动布局:

<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/home_app_bar_layout"
        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/home_toolbar"
            style="@style/AppTabStyle"
            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/home_tab_layout"
            style="@style/TabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>

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

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

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

我在 ViewPager 中有包含 RecyclerViews 的片段。因此,一切正常,工具栏隐藏,当 RecyclerView 滚动到底部并以其他方式显示时。但是,如果我稍微滚动一下 RecyclerView,则可能会以错误的状态显示 Toolbar。

初始状态: 初始状态

错误状态: 错误状态

我想要谷歌播放中的工具栏动画。是否可以使用设计支持库?有没有人非常CoordinatorLayout.Behavior适合这种情况?

4

0 回答 0