title: setting up scrolling fragments into Scrolling Activity
body: <p>I am using Android's predefined Scrolling Activity (collapsing toolbar layout), I want to replace the content layout by fragments ( using viewpager ). 
  I have tried modifying the scrolling activity layout by different ways but i am not be able to achieve the goal.</p>
  
  <p>I have attached an image which is my ultimate goal to achieve.</p>
  
  <p>Can anyone help me in editing the scrolling activity in such a way to achieve the goal ?</p>
  
  <h2>  <a href="https://i.stack.imgur.com/EY8bl.png" rel="nofollow noreferrer">Layout To Create</a></h2>
  
  <p><strong>content_layout.xml</strong></p>
  
  <hr>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;android.support.v4.widget.NestedScrollView 
  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"
  app:layout_behavior="@string/appbar_scrolling_view_behavior"
  tools:context=".activity.DetailsActivity"
  tools:showIn="@layout/activity_details"&gt;
  
  &lt;android.support.v4.view.ViewPager
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="match_parent"/&gt;
  
  
  &lt;/android.support.v4.widget.NestedScrollView&gt;
  </code></pre>
  
  <p><strong>main_activity.xml</strong></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"
  xmlns:tools="http://schemas.android.com/tools"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:fitsSystemWindows="true"
  tools:context=".activity.DetailsActivity"&gt;
  
  &lt;android.support.design.widget.AppBarLayout
      android:id="@+id/app_bar"
      android:layout_width="match_parent"
      android:layout_height="@dimen/app_bar_height"
      android:fitsSystemWindows="true"
      android:theme="@style/AppTheme.AppBarOverlay"&gt;
  
      &lt;android.support.design.widget.CollapsingToolbarLayout
          android:id="@+id/toolbar_layout"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:fitsSystemWindows="true"
          app:contentScrim="?attr/colorPrimary"
          app:layout_scrollFlags="scroll|exitUntilCollapsed"
          app:toolbarId="@+id/toolbar"&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/AppTheme.PopupOverlay" /&gt;
  
          &lt;RelativeLayout
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"&gt;
  
              &lt;android.support.v4.view.ViewPager
                  android:id="@+id/pager"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:layout_alignParentTop="true" /&gt;
  
              &lt;me.relex.circleindicator.CircleIndicator
                  android:id="@+id/indicator"
                  android:layout_width="match_parent"
                  android:layout_height="?attr/actionBarSize"
                  android:layout_alignParentBottom="true"
                  android:gravity="top"
                  android:paddingBottom="25dp" /&gt;
  
          &lt;/RelativeLayout&gt;
  
  
      &lt;/android.support.design.widget.CollapsingToolbarLayout&gt;
  
      &lt;/android.support.design.widget.AppBarLayout&gt;
  
      &lt;include layout="@layout/content_layout" /&gt;
  
      &lt;android.support.design.widget.FloatingActionButton
      android:id="@+id/fab"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_margin="@dimen/fab_margin"
      app:layout_anchor="@id/app_bar"
      app:layout_anchorGravity="bottom|end"
      app:srcCompat="@android:drawable/ic_dialog_email" /&gt;
  
   &lt;/android.support.design.widget.CoordinatorLayout&gt;
  </code></pre>
  
  <p><strong>MainActivity.java</strong></p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  private ViewPager mViewPager;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_details);
      Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
      setSupportActionBar(toolbar);
  
      mViewPager = findViewById(R.id.container);
  
      setupViewPager(mViewPager);
      mViewPager.setCurrentItem(0, true);
  
      FloatingActionButton fab = (FloatingActionButton) 
      findViewById(R.id.fab);
      fab.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              Snackbar.make(view, "Replace with your own action", 
              Snackbar.LENGTH_LONG)
                      .setAction("Action", null).show();
          }
      });
  }
  
  private void setupViewPager(ViewPager viewPager) {
      ViewPagerAdapter adapter = new 
      ViewPagerAdapter(getSupportFragmentManager());
      adapter.addFragment(new Frag1(), "Frag1");
      adapter.addFragment(new Frag2(), "Frag2);
      adapter.addFragment(new Frag3(), "Frag3");
      viewPager.setAdapter(adapter);
  }
  
  class ViewPagerAdapter extends FragmentPagerAdapter {
      private final List&lt;Fragment&gt; mFragmentList = new ArrayList&lt;&gt;();
      private final List&lt;String&gt; mFragmentTitleList = new ArrayList&lt;&gt;();
  
      public ViewPagerAdapter(FragmentManager manager) {
          super(manager);
      }
  
      @Override
      public Fragment getItem(int position) {
          return mFragmentList.get(position);
      }
  
      @Override
      public int getCount() {
          return mFragmentList.size();
      }
  
      public void addFragment(Fragment fragment, String title) {
          mFragmentList.add(fragment);
          mFragmentTitleList.add(title);
      }
  
      @Override
      public CharSequence getPageTitle(int position) {
          return mFragmentTitleList.get(position);
      }
  }
  
  
  }
  </code></pre>