title: Android - Unable to fix the Toolbar in a Collapsing Toolbar layout
body: <p>I am currently using CollapsingToolbar Layout in the upper portion of my layout. I want to collpase a particular portion (LinearLayout only) and keep the toolbar fixed on the top. I was able to fix the Toolbar position on top in another project and keep it from collapsing. However, for some reason, I am not able to fix the position of my toolbar. Any help will be appreciated. Here is my the XML of the layout:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.design.widget.CoordinatorLayout
  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:id="@+id/profile_coordinate_layout"
  &gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/app_bar_layout"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      &gt;
      &lt;android.support.design.widget.CollapsingToolbarLayout
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          app:layout_scrollFlags="scroll|enterAlways"
          android:layout_gravity="fill_vertical"
          android:fitsSystemWindows="true"
          app:layout_collapseMode="pin"
          app:expandedTitleMarginStart="?actionBarSize"
          app:contentScrim="?colorPrimary"
          &gt;
  
          &lt;!--|||||||||||||||||||||||||||||||||||||||||||||||||--&gt;
          &lt;!--|||||||||||||||Collection Profile and about||||||--&gt;
          &lt;!--|||||||||||||||||||||||||||||||||||||||||||||||||--&gt;
          &lt;LinearLayout
              android:id="@+id/ll_header"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:layout_marginTop="?actionBarSize"
              android:orientation="vertical"
              app:layout_collapseMode="pin"
              android:background="@drawable/gradient_feed_bg"
              &gt;
              &lt;include
                  layout="@layout/item_collection_profile" /&gt;
          &lt;/LinearLayout&gt;
  
  
          &lt;android.support.v7.widget.Toolbar
              android:id="@+id/toolbar"
              android:layout_width="match_parent"
              android:layout_height="?actionBarSize"
              android:background="@drawable/dark_primary_no_radius"
              app:layout_collapseMode="pin"
              android:elevation="@dimen/margin_4dp"
              &gt;
              &lt;include layout="@layout/action_bar_collection_profile"/&gt;
          &lt;/android.support.v7.widget.Toolbar&gt;
      &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  &lt;/android.support.design.widget.AppBarLayout&gt;
  
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/view_pager"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior"
      &gt;&lt;/android.support.v4.view.ViewPager&gt;
  &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p>I am loading another fragment on the ViewPager. and I am using the following code to load the toolbar.</p>
  
  <pre><code>findViewById(R.id.toolbar). setBackgroundResource(R.drawable.dark_primary_no_radius);
  setSupportActionBar((android.support.v7.widget.Toolbar)findViewById(R.id.toolbar));
  </code></pre>
  
  <p>And here is <strong>UPDATED</strong> the result: </p>
  
  <p><a href="https://i.stack.imgur.com/tfkTF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/tfkTF.png" alt="enter image description here"></a></p>
  
  <p>As you can see, in the second image, toolbar collapsed on the top. Any help will be highly appreciated.</p>
  
  <p>Thank you.</p>