我对android很新,并且在滚动期间尝试隐藏工具栏,并希望在滚动面相反时显示它。我按照我发现互联网的说明,但代码中缺少一些东西,不允许我实现这一点。下面显示的代码是我的活动布局,第二部分是活动内部的片段。虽然一切看起来都井井有条但我无法做到这一点。
<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">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/coordinatorLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".view.HomeActivity"> <!-- The ActionBar displayed at the top -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="55dp"
android:fitsSystemWindows="true"
android:theme="@style/SkorAdamThemeTeam.ActionBarTheme">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/mainCollapsing"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:titleEnabled="false"
app:scrimAnimationDuration="0"
app:statusBarScrim="@android:color/transparent"
app:contentScrim="@android:color/transparent"
android:fitsSystemWindows="true"
app:paddingStart="0dp"
app:paddingEnd="0dp"
android:layout_gravity="top"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax"
app:theme="@style/SkorAdamTheme.ActionBarTheme"
android:background="?attr/colorAccent">
</android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.CoordinatorLayout
android:id="@+id/container_body"
android:layout_width="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/container_toolbar_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
android:id="@+id/toolbar_bottom"
layout="@layout/toolbar_bottom" />
</LinearLayout>
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view_search"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="end"
android:background="#F6F6F6"
android:fitsSystemWindows="true"
app:headerLayout="@layout/search_layout"
app:menu="@menu/menu_search">
</android.support.design.widget.NavigationView>
<!-- The navigation drawer that comes from the left -->
<!-- Note that `android:layout_gravity` needs to be set to 'start' -->
<android.support.design.widget.NavigationView
android:id="@+id/nvView"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@color/colorPrimaryBlack"
app:itemTextColor="@color/light_grey"
app:itemBackground="@drawable/menu_divider"
app:menu="@menu/drawer_view"
app:headerLayout="@layout/navigation_drawer_header">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginTop="-8dp"
android:clickable="true"
android:orientation="horizontal" />
</android.support.design.widget.NavigationView>
</android.support.v4.widget.DrawerLayout>
<!-----------fragment------------->
<android.support.v7.widget.RecyclerView
android:background="#e0e7e8"
android:id="@+id/today_recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:nestedScrollingEnabled="false"
android:animateLayoutChanges="false" appbar_scrolling_view_behavior="@string/appbar_scrolling_view_behavior"
xmlns:android="http://schemas.android.com/apk/res/android"/>