0

我正在尝试将 AppBarLayout 与 Toolbar 和 Tabs 一起使用,以便在用户滚动时隐藏 Toolbar。

我尝试以与 Cheesesquare 示例完全相同的方式进行操作,但仍然无法正常工作。

这是我的 XML 代码:

<RelativeLayout
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"
tools:context="com.izzivizzi.avant2go.activities.ACLoginActivity"
android:background="@color/activity_background_light">

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        android:background="@color/green"
        android:theme="@style/AppTheme"
        app:layout_scrollFlags="scroll|enterAlways">

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/margin_big"
            android:layout_marginBottom="@dimen/margin_big"
            android:orientation="vertical"
            android:layout_gravity="center">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textColor="@color/white"
                android:textSize="30sp"
                android:text="@string/avantcar"/>

            <View
                android:layout_width="300dp"
                android:layout_height="1dp"
                android:layout_marginTop="5dp"
                android:background="@color/white" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginTop="5dp"
                android:layout_gravity="center"
                android:textColor="@color/white"
                android:textSize="18sp"
                android:text="@string/main_slogan"/>

        </LinearLayout>

    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/green"
        android:layout_below="@id/toolbar"
        app:tabIndicatorColor="@color/primary"
        app:tabSelectedTextColor="@color/white"
        app:tabTextColor="@color/primary"/>

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

<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/viewPager"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appbar"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</RelativeLayout>

我也尝试用 CoordinatorLayout 替换 RelativeLayout 但它不起作用。

4

0 回答 0