title: Change AppBarLayout height programmatically in Android
body: <p>I'm trying to implement Flexible Space with image pattern, using <a href="http://blog.grafixartist.com/toolbar-animation-with-android-design-support-library/" rel="noreferrer">this tutorial</a>.</p>
  
  <p>Everything works fine.</p>
  
  <p>Notice the height definition of the AppBarLayout which is 192dp.</p>
  
  <p>I'd like to make the height 1/3 of the screen instead, to match <a href="http://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0B6Okdz75tqQscXNQY3dNdVlYeTQ/patterns-scrolling-techniques_flex_space_image_xhdpi_003.webm" rel="noreferrer">this google example for the pattern here</a>.</p>
  
  <p>Here's the code in the activity's onCreate (the layout xml is exactly the same as in the tutorial):</p>
  
  <pre><code>AppBarLayout appbar = (AppBarLayout)findViewById(R.id.appbar);
  float density = getResources().getDisplayMetrics().density;
  float heightDp = getResources().getDisplayMetrics().heightPixels / density;
  appbar.setLayoutParams(new CoordinatorLayout.LayoutParams(LayoutParams.MATCH_PARENT, Math.round(heightDp / 3)));
  </code></pre>
  
  <p>But for some reason, the result is not what I'm expecting. I can't see the app bar at all with this code. (without the code, the height shows as expected but it's from XML and can't be set dynamically).</p>