title: Android CollapsingToolbar/ AppBarLayout scroll behind status bar behaviour top padding
body: <p>I'd like to use <code>CoordinatoryLayout</code>, <code>AppBarLayout</code> and <code>CollapsingToolbarLayout</code> to create a layout that resembles the below example from Google Calendar.</p>
  
  <p><a href="https://i.stack.imgur.com/sPfmS.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sPfmS.gif" alt="Desired Google Calendar scroll behaviour"></a></p>
  
  <p>The key things I'm trying to replicate:</p>
  
  <ul>
  <li>Scrolling the content behind the status bar</li>
  <li>Rounded corners at the top of the scroll container</li>
  <li>Enough room at the top of the screen for the header to not look squashed</li>
  </ul>
  
  <p><strong>The Question</strong>
  Google Calendar appears to be growing the scroll container as the user scrolls. How would I go about doing this or something similar to achieve the look I'm after?</p>
  
  <p>I've put together a quick example of what I'm trying to build:</p>
  
  <p><strong>activity_scrolling.xml</strong></p>
  
  <pre><code>&lt;androidx.coordinatorlayout.widget.CoordinatorLayout 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:layout_width="match_parent"
      android:layout_height="match_parent"
      android:animateLayoutChanges="true"
      tools:context="uk.co.exampleapplication.ScrollingActivity"&gt;
  
      &lt;com.google.android.material.appbar.AppBarLayout
          android:id="@+id/app_bar_layout"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"&gt;
  
          &lt;com.google.android.material.appbar.CollapsingToolbarLayout
              android:id="@+id/collapsing_toolbar"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;
  
              &lt;include
                  android:id="@+id/lay_header"
                  layout="@layout/layout_header" /&gt;
  
          &lt;/com.google.android.material.appbar.CollapsingToolbarLayout&gt;
  
          &lt;androidx.constraintlayout.widget.ConstraintLayout
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:background="@drawable/scroll_header_background"
              android:elevation="16dp"
              android:paddingBottom="12dp"&gt;
  
              &lt;TextView
                  android:id="@+id/sectionTitleText"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginStart="16dp"
                  android:layout_marginTop="32dp"
                  android:text="Title"
                  app:layout_constraintStart_toStartOf="parent"
                  app:layout_constraintTop_toTopOf="parent" /&gt;
  
              &lt;Button
                  android:id="@+id/filter_button"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_marginTop="22dp"
                  android:layout_marginEnd="16dp"
                  android:text="Button"
                  app:layout_constraintEnd_toEndOf="parent"
                  app:layout_constraintTop_toTopOf="parent" /&gt;
  
          &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  
      &lt;/com.google.android.material.appbar.AppBarLayout&gt;
  
      &lt;androidx.core.widget.NestedScrollView
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_behavior="@string/appbar_scrolling_view_behavior"
          tools:context=".ScrollingActivity"
          tools:showIn="@layout/activity_scrolling"&gt;
  
          &lt;TextView
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_margin="@dimen/text_margin"
              android:text="@string/large_text" /&gt;
  
      &lt;/androidx.core.widget.NestedScrollView&gt;
  
  &lt;/androidx.coordinatorlayout.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><strong>layout_header.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;androidx.constraintlayout.widget.ConstraintLayout 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/header"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:paddingHorizontal="16dp"
      android:paddingTop="60dp"
      android:paddingBottom="40dp"
      app:layout_collapseMode="parallax"
      tools:ignore="HardcodedText"&gt;
  
      &lt;TextView
          android:id="@+id/title"
          android:layout_width="match_parent"
          android:layout_height="24dp"
          android:layout_marginTop="8dp"
          android:layout_marginEnd="16dp"
          android:text="Title"
          android:textColor="#FFF"
          android:textSize="20sp"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toTopOf="parent" /&gt;
  
      &lt;TextView
          android:id="@+id/subtitle"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:text="Subtitle"
          android:textColor="#FFF"
          android:textSize="16sp"
          app:layout_constraintHorizontal_bias="0.0"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintTop_toBottomOf="@+id/title" /&gt;
  
  &lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;
  </code></pre>
  
  <p><strong>scroll_header_background.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;shape xmlns:android="http://schemas.android.com/apk/res/android"
      android:shape="rectangle"&gt;
      &lt;corners
          android:bottomLeftRadius="0dp"
          android:bottomRightRadius="0dp"
          android:topLeftRadius="20dp"
          android:topRightRadius="20dp" /&gt;
      &lt;solid android:color="#FFFFFF" /&gt;
      &lt;size
          android:width="64dp"
          android:height="64dp" /&gt;
  &lt;/shape&gt;
  </code></pre>
  
  <p>My attempt is included below. The header scrolls behind the toolbar as desired but I'd like some additional top padding above my views (about the height of the top inset/ status bar would be sufficient). Google Calendar appears to be solving this by having the container grow as the user scrolls. </p>
  
  <p><a href="https://i.stack.imgur.com/uVtdY.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uVtdY.gif" alt="My attempt at scrolling"></a><a href="https://i.stack.imgur.com/S3Q2C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/S3Q2C.png" alt="Screenshot"></a></p>