滚动停止时工具栏不会隐藏

时间:2017-02-09 05:17:06

标签: xml android-layout android-toolbar android-nestedscrollview

我试图在用户空闲时隐藏我的工具栏,并在用户向上滚动时显示。使用下面的布局,不幸的是我得到了一个“接近但没有雪茄”的结果......正如你所看到的那样,工具栏是一个空间,它应该达到预期的效果。

<?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.v4.widget.SwipeRefreshLayout

                    android:id="@+id/swiperefreshsharing"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:background="@drawable/post_back">


                    <android.support.v7.widget.RecyclerView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:id="@+id/posted_list"
                        app:layout_behavior="@string/appbar_scrolling_view_behavior">
                    </android.support.v7.widget.RecyclerView>


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

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

                <android.support.v7.widget.Toolbar
                    android:id="@+id/theToolbar"
                    app:layout_scrollFlags="scroll|enterAlways|snap"
                    app:contentInsetLeft="0dp"
                    app:contentInsetStart="0dp"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="@drawable/actionbar_background"
                    android:elevation="4dp"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light">


                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal"
                        android:paddingRight="10dp"
                        android:paddingLeft="10dp"
                        android:paddingTop="5dp">


                        <ImageView
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            android:elevation="6dp"
                            android:background="?android:selectableItemBackground"
                            android:layout_height="wrap_content"
                            app:srcCompat="@drawable/action_setup"
                            android:layout_alignParentTop="true"
                            android:id="@+id/action_setup" />

                        <ImageView
                            android:layout_width="0dp"
                            android:layout_height="wrap_content"
                            app:srcCompat="@drawable/ceppi_half"
                            android:id="@+id/ceppi"
                            android:layout_alignParentBottom="true"
                            android:layout_weight="1" />

                        <ImageView
                            android:layout_height="wrap_content"
                            android:background="?android:selectableItemBackground"
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            app:srcCompat="@drawable/post_button"
                            android:layout_alignParentTop="true"
                            android:layout_toEndOf="@+id/action_setup"
                            android:id="@+id/action_post" />

                        <ImageView
                            android:layout_height="wrap_content"
                            android:background="?android:selectableItemBackground"
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            app:srcCompat="@drawable/logoutbtn"
                            android:layout_alignParentTop="true"
                            android:layout_toEndOf="@+id/action_post"
                            android:id="@+id/action_logout" />

                        <ImageView
                            android:layout_height="wrap_content"
                            android:background="?android:selectableItemBackground"
                            android:layout_width="0dp"
                            android:layout_weight="1"
                            app:srcCompat="@drawable/tutorial"
                            android:layout_centerVertical="true"
                            android:id="@+id/action_tutorial" />
                    </LinearLayout>

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


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

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

我已经有了显示和隐藏机制,但不幸的是......闲置时看起来像this

当我向上滚动时就像this一样......

如果我能让那个工具栏成为图2中不可见空间的地方......一切都会很完美。

非常感谢您的帮助

0 个答案:

没有答案