Create a Scrolling Activity with a Collapsing Toolbar

Introduction
Before you start this tutorial, you must be already proficient in creating Toolbars and Activities. This tutorial is a continuation of the tutorial Create a Toolbar. If your Activity still doesn't have a Toolbar with a CoordinatorView, follow the previous tutorial before continue.

In this tutorial, you will learn how to create a Nested ScrollView combined with a Collapsing Toolbar. In addition, you will learn how to place a Floating Action Button between the two views and make it disappear when you start scrolling. If you don't know how to place a Floating Action Button, follow the tutorial Create a Floating Action Button before continue.

Creating a Nested ScrollView
Replace the LinearLayout or whichever layout current holds your main content. Your code should look like this:

Insert all the content of your activity inside the NestedScrollView. Remember the NestedScrollView will be placed inside a CoordinatorLayout, just as the other layouts were placed, so it will work together with the Toolbar, Floating Action Button and other elements you include.

Creating the Collapsing Toolbar
Inside your activity_main.xml, you already have an AppBarLayout, and inside it, a Toolbar. Create a CollapsingToolBar layout and set it as a child of AppBarLayout, and as a the parent of the Toolbar.



Then, add the following tag to your Toobar:

By now, your layout file should look like this:

Placing a Floating Action Button between the two views
If you already have a Floating Action Button in your activity, you can follow the steps bellow. If not, follow the Create a Floating Action Button tutorial.

Anchor your Floating Action Button to the AppBarLayout by using the following tag:

It will now be shown between the Expanded Toolbar and the Nested Scrollview. When you start scrolling, it will disappear and reappear when you reach the top again.

When you finish, your layout file should look like this:

Conclusion
Your activity now has a working Collapsion Toolbar, a Nested Scrollview and a Floating Action Button.

You now know how to create Nested Scrollviews to display an amount of content bigger than the screen, and how to make the Toolbar animate to a smaller or bigger size. You also know how to place an FAB between the views and how to make it only appear when the Toolbar is big.