title: Collapsible Toolbar: Set how much the toolbar should be collapsed in onCreate
body: <p>I'm creating a <code>ListView</code> and its corresponding <code>DetailView</code> application.
  My <code>ListView</code> has items which if clicked take the user to the <code>DetailViewActivity</code>.</p>
  
  <p>On the <code>DetailViewActivity</code>, I've implemented a Collapsible Toolbar.
  Now, every time the <code>DetailViewActivity</code> is opened, a different image (with different dimensions) is set onto the <code>ImageView</code> within the Collapsible Toolbar.</p>
  
  <p>I want that the <code>Toolbar</code> should be open up to a certain height by default (say 256dp), but if the image height is greater than that, the user should be able to pull down to view the rest of the image. (exactly like Whatsapp)</p>
  
  <p>I've managed to programmatically set the height of the <code>Toolbar</code> each time I open the activity, but the problem is, the <code>Toolbar</code> is always fully expanded. So if the image is larger, the Toolbar by default is very big. I want it to be collapsed to 256dp irrespective of the height of the image.</p>
  
  <hr>
  
  <p>The code for my layout is:</p>
  
  <pre><code>&lt;RelativeLayout
      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"&gt;
  
      &lt;android.support.design.widget.CoordinatorLayout
          android:id="@+id/rootLayout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"&gt;
  
          &lt;android.support.design.widget.AppBarLayout
              android:id="@+id/appbar"
              android:layout_width="match_parent"
              android:layout_height="@dimen/app_bar_height"
              android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"&gt;
  
              &lt;android.support.design.widget.CollapsingToolbarLayout
                  android:id="@+id/collapsingToolbarLayout"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  app:contentScrim="?attr/colorPrimary"
                  app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
                  app:layout_scrollFlags="scroll|exitUntilCollapsed"&gt;
  
                  &lt;ImageView
                      android:id="@+id/image"
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:scaleType="centerCrop"
                      android:src="@drawable/background_navdrawer"
                      app:layout_collapseMode="parallax"
                      app:layout_collapseParallaxMultiplier="0.7"/&gt;
  
                  &lt;View
                      android:layout_width="match_parent"
                      android:layout_height="match_parent"
                      android:layout_marginTop="130dp"
                      android:background="@drawable/gradient_header_background"
                      app:layout_collapseMode="parallax"
                      app:layout_collapseParallaxMultiplier="0.1"/&gt;
  
                  &lt;android.support.v7.widget.Toolbar
                      android:id="@+id/toolbar"
                      android:layout_width="match_parent"
                      android:layout_height="?attr/actionBarSize"
                      app:layout_collapseMode="pin"
                      app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                      app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"/&gt;
  
  
              &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  
          &lt;/android.support.design.widget.AppBarLayout&gt;
  
  
          &lt;android.support.v4.widget.NestedScrollView
              android:id="@+id/detail_nested_scroll_view"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              app:layout_behavior="@string/appbar_scrolling_view_behavior"&gt;
  
              &lt;FrameLayout
                  android:id="@+id/detail_container"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  tools:ignore="MergeRootFrame"/&gt;
  
          &lt;/android.support.v4.widget.NestedScrollView&gt;
  
          &lt;LinearLayout
              android:layout_width="match_parent"
              android:layout_height="12dp"
              android:orientation="vertical"
              app:layout_anchor="@+id/appbar"
              app:layout_anchorGravity="bottom"&gt;
  
              &lt;View
                  android:id="@+id/toolbar_shadow_transparent"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/toolbar_elevation"
                  android:background="@color/transparent"/&gt;
  
              &lt;View
                  android:id="@+id/toolbar_shadow"
                  android:layout_width="match_parent"
                  android:layout_height="@dimen/toolbar_elevation"
                  android:background="@drawable/dropshadow"/&gt;
          &lt;/LinearLayout&gt;
  
  
          &lt;com.github.clans.fab.FloatingActionButton
              android:id="@+id/action_edit"
              style="@style/MenuButtonsStyle"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_marginRight="10dp"
              android:src="@drawable/ic_edit"
              app:layout_anchor="@+id/appbar"
              app:layout_anchorGravity="bottom|right|end"/&gt;
  
      &lt;/android.support.design.widget.CoordinatorLayout&gt;
  
      &lt;ImageView
          android:id="@+id/detail_back_arrow_land"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:visibility="gone"/&gt;
  
      &lt;TextView
          android:id="@+id/course_name_textview"
          android:layout_width="0dp"
          android:layout_height="0dp"
          android:visibility="gone"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <hr>
  
  <p>And in my Activity, I've found the height and set it to the <code>Toolbar</code> like this:</p>
  
  <pre><code>appBar = (AppBarLayout) findViewById(R.id.appbar);
  CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) appBar.getLayoutParams();
  lp.height = my_bitmap.getHeight();
  DetailActivity.appBar.setLayoutParams(lp);
  DetailActivity.mImageView.setImageBitmap(my_bitmap);
  </code></pre>
  
  <hr>
  
  <p>I'm attaching screenshots to make my point clearer.</p>
  
  <p>This is exactly how tall I want my Toolbar to be every time the activity gets launched:
  <a href="https://i.stack.imgur.com/7haxO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7haxO.png" alt="enter image description here"></a></p>
  
  <p>And this is what I get from my code:</p>
  
  <p><a href="https://i.stack.imgur.com/SSBdt.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SSBdt.png" alt="enter image description here"></a></p>
  
  <p>Now, I could hardcode the height to 256dp in code, but then the user will not be able to scroll down to see the rest of the image. Please suggest.</p>
  
  <p>Thank you for your response.
  Any response could get me started</p>