title: Why is scrolling in NavigationView dependent on outside xml elements?
body: <p>I'm placing a table of contents menu inside a right-sided NavigationView.  Here is my code that works:</p>
  
  <pre><code>&lt;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:layout_gravity="right"
      tools:openDrawer="start"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/top_nav_toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              android:elevation="4dp"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light"&gt;
          &lt;/android.support.v7.widget.Toolbar&gt;
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;!-- The main content gets loaded in here. --&gt;
      &lt;LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:id="@+id/grandparent_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          tools:context="my.Activity"&gt;
  
          &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/fragment_container"
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
          &lt;/FrameLayout&gt;
      &lt;/LinearLayout&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/toc_drawer_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="end"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/burger_menu_header"
          app:theme="@style/TableOfContents_TextAppearance"
          app:menu="@menu/burger_menu_drawer_items"
          &gt;
      &lt;/android.support.design.widget.NavigationView&gt;
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>In a previous version of the code, I had the NavigationView above the main content-holding LinearLayout.  Like this:</p>
  
  <pre><code>&lt;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:layout_gravity="right"
      tools:openDrawer="start"&gt;
  
      &lt;android.support.design.widget.AppBarLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/top_nav_toolbar"
              android:layout_width="match_parent"
              android:layout_height="?attr/actionBarSize"
              android:background="?attr/colorPrimary"
              android:elevation="4dp"
              app:popupTheme="@style/ThemeOverlay.AppCompat.Light"&gt;
          &lt;/android.support.v7.widget.Toolbar&gt;
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;android.support.design.widget.NavigationView
          android:id="@+id/toc_drawer_view"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:layout_gravity="end"
          android:fitsSystemWindows="true"
          app:headerLayout="@layout/burger_menu_header"
          app:theme="@style/TableOfContents_TextAppearance"
          app:menu="@menu/burger_menu_drawer_items"
          &gt;
      &lt;/android.support.design.widget.NavigationView&gt;
  
      &lt;!-- The main content gets loaded in here. --&gt;
      &lt;LinearLayout
          xmlns:android="http://schemas.android.com/apk/res/android"
          xmlns:tools="http://schemas.android.com/tools"
          xmlns:app="http://schemas.android.com/apk/res-auto"
          android:id="@+id/grandparent_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:orientation="vertical"
          tools:context="my.Activity"&gt;
  
          &lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:id="@+id/fragment_container"
              android:layout_width="match_parent"
              android:layout_height="match_parent"&gt;
          &lt;/FrameLayout&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/android.support.v4.widget.DrawerLayout&gt;
  </code></pre>
  
  <p>In that version, the system (both on an emulator and hardware test device) displayed the right-sided drawer, and displayed the first few elements of the menu, but I could not scroll to the bottom of the menu.  The scroll bar would appear if I turned it on manually in the xml code, but it just didn't know there was any content beyond the immediately visible.</p>
  
  <p>My question is why?  What is the drawing logic behind the scenes that makes the scrolling magic work?</p>
  
  <p>For completeness, burger_menu_header.xml looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:background="@drawable/toc_nav_bar"
  android:gravity="bottom"
  android:orientation="vertical"
  android:paddingBottom="@dimen/activity_vertical_margin"
  android:paddingLeft="@dimen/activity_horizontal_margin"
  android:paddingRight="@dimen/activity_horizontal_margin"
  android:paddingTop="@dimen/activity_vertical_margin"
  android:theme="@style/ThemeOverlay.AppCompat.Dark"&gt;
  &lt;TextView
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:paddingTop="@dimen/nav_header_vertical_spacing"
      android:text="Table of Contents"
      android:textAppearance="@style/TextAppearance.AppCompat.Body1"/&gt;
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>and burger_menu_drawer_items.xml looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;menu xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;item
          android:id="@+id/nav_chapter_0"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Introduction"/&gt;
  
      &lt;item
          android:id="@+id/nav_chapter_1"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 1 - The Adventure"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_2"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 2 - Our Heroes Go Sailing"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_3"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 3 - The Ship Is LostAtSeaFarAway"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_4"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 4 - Skipper Wins!"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_5"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 5"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_6"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 6"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_7"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 7"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_8"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 8"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_9"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 9"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_10"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 10"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_11"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 11 - No Way Is This Happening, She Cried"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_12"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 12 - The End?"/&gt;
      &lt;item
          android:id="@+id/nav_chapter_13"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 13 - But Wait..."/&gt;
      &lt;item
          android:id="@+id/nav_chapter_14"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 14 - But Wait..."/&gt;
      &lt;item
          android:id="@+id/nav_chapter_15"
          android:icon="@drawable/ic_radio_button_unchecked_black_24dp"
          android:title="Chapter 14 - Nah, It Was Nothing"/&gt;
  &lt;/menu&gt;
  </code></pre>