I am trying to implement a layout with a CollapsingToolbarLayout
inside a DrawerLayout
. The whole acitivty_main.xml
looks like this:
<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/activity_main__drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The CoordinatorLayout is used to coordinate (rly) scroll events between different views -->
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The AppBar (everything above the scrolling content) -->
<android.support.design.widget.AppBarLayout
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="@+id/activity_main__app_bar"
android:fitsSystemWindows="true"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/activity_main__collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/appbar_size_expanded"
android:minHeight="?attr/actionBarSize"
app:expandedTitleMarginEnd="16dp"
app:expandedTitleMarginStart="72dp"
app:expandedTitleMarginBottom="32dp"
app:expandedTitleTextAppearance="@style/ExpandedAppBarTitle"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<android.support.v7.widget.Toolbar
android:id="@+id/activity_main__toolbar"
android:layout_height="?attr/actionBarSize"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:background="?attr/colorPrimary"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<!-- The scrolling content view -->
<android.support.v4.widget.NestedScrollView
android:id="@+id/activity_main__content_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#CCC333"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<!-- The add button -->
<android.support.design.widget.FloatingActionButton
android:id="@+id/activity_main__floating_action_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:src="@drawable/ic_add_white_24dp"
android:clickable="true"
app:layout_anchor="@+id/activity_main__app_bar"
app:layout_anchorGravity="bottom|right|end"
app:borderWidth="0dp"
app:elevation="@dimen/fab_elevation" />
</android.support.design.widget.CoordinatorLayout>
<!-- The navigation drawer -->
<android.support.design.widget.NavigationView
android:id="@+id/activity_main__navigation_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="@android:color/white"
app:menu="@menu/menu_drawer"
app:headerLayout="@layout/drawer_navigation_header" />
</android.support.v4.widget.DrawerLayout>
The layout and app structure is loosely based on this tutorial by codepath, where I have changed the FrameLayout
for a NestedScrollView
(even though the effect appears with both).
Now the view I intend to use for the actual content has some weird padding (I have used a background color to clarify where it is actually rendered):
Where did I mess up?
Try to remove the : exitUntilCollapsed
Into CollapsingToolbarlayout you have now this code
It's Design Library's fault. Layouts "shorter" than screen height cause gaps, misbehaviour in collapsing/unfolding
<CollapsingToolbarLayout>
(i.e. you need to drag outside of collapsed area to unfold it again etc, etc, etc. It's just quite buggy at the moment or writing this answer (it will, hopefully be fixed some day, but I got no clue when this is going to happen).