向上滚动时隐藏工具栏和页脚

时间:2017-10-15 15:29:36

标签: android android-recyclerview android-toolbar android-coordinatorlayout

我想在我的一项活动中使用 CoordinatorLayout

活动的布局在顶部包含工具栏,在中间包含 RecyclerView ,在底部包含 RelativeLayout (页脚)。

当用户向上刷 RecyclerView 时,我想隐藏工具栏

到目前为止我取得的成就:

当我向上滑动时,工具栏会隐藏,但页脚(之前隐藏的)会重新出现。我希望工具栏和页脚以某种方式链接,以便在用户滑动时同时隐藏它们。

我听说过行为,但我不知道如何创建它们(我只是使用默认的)。

我的活动布局:

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <!-- toolbar -->
            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:background="?attr/colorPrimary"
                android:layout_width="match_parent"
                ....
                app:layout_scrollFlags="scroll|enterAlways">
                <RelativeLayout
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content">
                    ....
                </RelativeLayout>
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_above="@+id/footer"
                android:layout_alignParentTop="true">
                <!-- content -->
                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerview"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scrollbars="vertical" />
            </RelativeLayout>

            <!-- footer -->
            <RelativeLayout
                android:id="@+id/footer"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true">
                ....
            </RelativeLayout>
        </RelativeLayout>
    </android.support.design.widget.CoordinatorLayout>
</LinearLayout>

<!-- The navigation drawer -->
<ListView android:id="@+id/right_drawer"
    android:layout_width="@dimen/drawer_width"
    android:layout_height="match_parent"
    android:layout_gravity="end"
    android:divider="@android:color/transparent"
    android:dividerHeight="1dp"
    android:background="?attr/drawerBackgroundColor"/>

</android.support.v4.widget.DrawerLayout>

0 个答案:

没有答案
相关问题