title: Anchor top content to BottomSheet
body: <p>I have a FrameLayout (teaserContainer) and BottomSheet (invitesContainer). The FrameLayout is outside (and above) the BottomSheet. I want the FrameLayout shrink and follow the BottomSheet, so the FremeLayout collapses as the BottomSheet expands. </p>
  
  <p>What happens now is that the FrameLayout occupies the whole page because of its <code>android:layout_height="match_parent"</code> but if I set it to <code>android:layout_height="wrap_content"</code> it shows behind the BottomSheet and vertically centred like a FAB would.</p>
  
  <p>I want that when the BottomSheet (invitesContainer) is fully expanded the FrameLayout (teaserContainer) should occupy the rest of the screen up to the toolbar.</p>
  
  <p>All examples of anchoring views to the BottomSheet involve a FAB, so not any help to me here.</p>
  
  <pre><code>&lt;android.support.design.widget.CoordinatorLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      tools:context=".social.friends.FriendsListFragment"&gt;
  
      &lt;FrameLayout
          android:id="@+id/teaserContainer"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:background="@color/white"
          android:fitsSystemWindows="true"
          android:gravity="center"
          android:orientation="vertical"
          android:visibility="gone"
          app:layout_anchor="@+id/invitesContainer"
          app:layout_anchorGravity="top"&gt;
  
          &lt;com.myapp.android.common.social.friends.views.FriendsTeaser
              android:id="@+id/teaser"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layout_gravity="center_vertical"
              app:friendsTeaserState="EMPTY" /&gt;
      &lt;/FrameLayout&gt;
  
      &lt;LinearLayout
          android:id="@+id/invitesContainer"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:background="@color/white"
          android:clickable="true"
          android:focusable="true"
          android:orientation="vertical"
          app:behavior_hideable="true"
          app:behavior_peekHeight="0dp"
          app:layout_behavior="android.support.design.widget.BottomSheetBehavior"&gt;
  
          &lt;View
              android:layout_width="match_parent"
              android:layout_height="1dp"
              android:alpha="0.1"
              android:background="@color/body" /&gt;
  
          &lt;com.myapp.android.common.social.friends.views.FriendsConnectItem
              android:id="@+id/connectFacebook"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:friendsConnectType="facebook" /&gt;
  
          &lt;com.myapp.android.common.social.friends.views.FriendsConnectItem
              android:id="@+id/connectContacts"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:friendsConnectType="contacts" /&gt;
  
          &lt;com.myapp.android.common.social.friends.views.FriendsConnectItem
              android:id="@+id/share"
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              app:friendsConnectType="invite" /&gt;
      &lt;/LinearLayout&gt;
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><strong>--------------------------------------------------------------------------------------------------------------</strong></p>
  
  <p><strong>Solution:</strong>
  <em>This is a Kotlin version of Vadim's suggestion</em></p>
  
  <pre><code>BottomSheetBehavior.from(invitesContainer).setBottomSheetCallback(object :
      BottomSheetBehavior.BottomSheetCallback() {
      override fun onStateChanged(bottomSheet: View, newState: Int) {
      }
  
      override fun onSlide(bottomSheet: View, slideOffset: Float) {
          val currentHeight = teaserContainer.height - bottomSheet.height
          val bottomSheetShiftDown = currentHeight - bottomSheet.top
          teaserContainer.setPadding(
              0,
              0,
              0,
              (bottomSheet.height + bottomSheetShiftDown)
          )
      }
  })
  </code></pre>