I had a strange problem with the new Android design support library ( http://android-developers.blogspot.com.ar/2015/05/android-design-support-library.html ). If I put additional content (for example, LinearLayout) in the AppBarLayout along with the ToolBar and switch the visibility of this content, then the dead space will be displayed at the top of the fragment content to switch fragments.
AppBarLayout does not seem to resize the parent Layout coordinator correctly when the visibility of the content is switched. I have my CoordinatorLayout wrapped in DrawerLayout. I want to switch the visibility of the optional LinearLayout to AppBarLayout depending on which fragment is shown.
Here is my main.xml file for MainActivity:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent" android:fitsSystemWindows="true"> <android.support.design.widget.CoordinatorLayout android:layout_height="match_parent" android:layout_width="match_parent"> <android.support.design.widget.AppBarLayout android:id="@+id/appBarLayout" 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="?attr/actionBarSize"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:gravity="center_vertical""> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:gravity="start" android:text="Hello"/> </LinearLayout> </android.support.design.widget.AppBarLayout> <FrameLayout app:layout_behavior="@string/appbar_scrolling_view_behavior" android:id="@+id/content_frame" android:layout_width="match_parent" android:layout_height="match_parent"/> </android.support.design.widget.CoordinatorLayout> <android.support.design.widget.NavigationView android:id="@+id/navigation" android:layout_width="wrap_content" android:layout_height="match_parent" android:layout_gravity="start" app:menu="@menu/drawer"/> </android.support.v4.widget.DrawerLayout>
source share