Android CoordinatorLayout is a super-powered FrameLayout. It has a lot more to offer than it seems. It has additional level of control over it’s child views. It coordinates the animations and transitions of child views with one another.
Let’s create a new Android Studio project and choose the Basic Activity template that has CoordinatorLayout by default. The layout consists of a Floating Action Button. Clicking it displays a SnackBar as shown below.

Did you notice that the Floating Action Button animates up to make way for the SnackBar and comes back when the SnackBar disappear?
This is no magic. It’s how the Floating Action Button behaves inside a CoordinatorLayout.
Note : CoordinatorLayout can also expand the ToolBar to show more content or collapse it while scrolling, something that is commonly seen when you scroll a WhatsApp User’s profile screen. Don’t worry, we’ll look into this in a later tutorial.
A question that would be popping up in our heads now – How does the CoordinatorLayout know what to do with the child view? The answer lies in the next section.
CoordinatorLayout Behaviors
The FAB within a CoordinatorLayout has been specified a default Behavior that causes it to animate accordingly when another view interacts with it.
Do a Ctrl/CMD+ Click on the FloatingActionButton in the layout/activity and you shall see a Behavior has been defined on the class with an annotation.
It should look like this:
@CoordinatorLayout.DefaultBehavior(FloatingActionButton.Behavior.class)
FloatingActionButton.Behavior is the default Behavior class used on the FAB.
We can define our own Behaviors by extending the class CoordinatorLayout.Behavior.
Here T is the class whose Behavior we wish to define. In the above case it is CoordinatorLayout.Behavior.
The Behaviors only work on the direct child of the CoordinatorLayout.
It’s necessary for the CoordinatorLayout to be the root layout of the activity
Upvote and Follow you. Follow me and upvote all my posts. Comment 'something' on any of my post and i'll do the same. Come lets earn together @byltc
Hi! I am a robot. I just upvoted you! I found similar content that readers might be interested in:
https://www.journaldev.com/12790/android-coordinatorlayout