title: Hiding AppBarLayout and giving its space to the remaining view
body: <p>I have a pretty standard layout using the new design libraries:</p>
  
  <p></p>
  
  <pre><code>&lt;AppBarLayout&gt;
      &lt;CollapsingToolbarLayout&gt;
          &lt;ImageView/&gt;
          &lt;Toolbar/&gt;
      &lt;/CollapsingToolbarLayout&gt;
  &lt;/AppBarLayout&gt;
  
  &lt;android.support.v4.widget.NestedScrollView/&gt; &lt;!-- content here --&gt;
  </code></pre>
  
  <p></p>
  
  <p>What I'm trying to do is to completely hide the whole <code>AppBarLayout</code> programmatically, to temporarily get rid of the <code>Toolbar</code> and its collapsing feature.</p>
  
  <p>So I'm calling this:</p>
  
  <pre><code>private void disableCollapsing() {
      AppBarLayout.LayoutParams p = (AppBarLayout.LayoutParams) collapsingToolbarLayout.getLayoutParams();
      p.setScrollFlags(0);
      collapsingToolbarLayout.setLayoutParams(p);
  }
  </code></pre>
  
  <p>to disable the collapsing behavior (works well), and finally this:</p>
  
  <pre><code>@Override
  public void hide() {
      final AppBarLayout layout = (AppBarLayout) findViewById(R.id.appbar);
  
      layout.animate().translationY(-layout.getHeight())
              .setListener(new AnimatorListenerAdapter() {
                  @Override
                  public void onAnimationEnd(Animator animation) {
                      super.onAnimationEnd(animation);
                      layout.setVisibility(View.GONE);
                  }
              }).start();
  }
  </code></pre>
  
  <p>I make the AppBarLayout translate to the top (works smoothly), and at the end of the animation set is visibility to <code>View.GONE</code>.</p>
  
  <h2>Issue</h2>
  
  <p>At the end of the animation, no matter I also set the visibility to GONE, I can't get the space that was previously occupied by the <code>AppBarLayout</code>. My NestedScrollView remains confined in the lower half of the screen, as if the AppBarLayout was still there (which is not). How can I fix it?</p>
  
  <p>Before hiding:</p>
  
  <p><img src="https://i.stack.imgur.com/K52da.png" alt="Before"></p>
  
  <p>After hiding (AppBar translated to the top):</p>
  
  <p><img src="https://i.stack.imgur.com/vziXy.png" alt="After"></p>
  
  <p>As you can see, the top space is empty and unreachable. The scroll view scrolls inside the margins it had before, as if the visibility change was not measured by the <code>CoordinatorLayout</code>.</p>
  
  <ul>
  <li><p>I have tried calling <code>coordinator.requestLayout()</code>, with no success.</p></li>
  <li><p>I also tried setting the AppBarLayout as an <code>app:anchor</code> for my NestedScrollView, but that screws things up - scroll view ends up taking the whole screen even before hiding.</p></li>
  <li><p>I was thinking of a custom <code>Behavior</code> to be set on the scroll view when entering this <em>hidden-AppBar mode</em>, but I can't get started on that.</p></li>
  </ul>