Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is CoordinatorLayout?

Just had a look at the demo app of new Android support design library. It's provided by Chris Banes on github. Throught the app, CoordinatorLayout is used Heavily. Also, many of the support design library classes such as FloatingActionButton, SnackBar, AppBarLayout etc. behaves differently when used inside CoordinatorLayout.

Can someone please shed some lights on what is CoordinatorLayout and how it is different from other ViewGroups in android, or at least provide correct path towards learning CoordinatorLayout.

like image 703
jimmy0251 Avatar asked May 29 '15 18:05

jimmy0251


People also ask

What is CoordinatorLayout and ConstraintLayout?

Use Coordinatorlayout as the top-level application decor. It will usually used to layout AppBarLayout , FloatingActionButton , and the main body of your screen, say NestedScrollView . Inside the NestedScrollView use ConstraintLayout to describe the rest of the layout as a flat hierarchy.

What is Android coordinator layout?

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.

How do you use coordinate layout?

By specifying Behaviors for child views of a CoordinatorLayout you can provide many different interactions within a single parent and those views can also interact with one another. View classes can specify a default behavior when used as a child of a CoordinatorLayout by implementing the AttachedBehavior interface.

What is FrameLayout?

FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.

What is a coordinatorlayout in Android?

The CoordinatorLayout is a new layout, introduced with the Android Design Support Library. The CoordinatorLayout is a super-powered FrameLayout (according to the official documentation ). If you have used a FrameLayout before, you should be very comfortable using CoordinatorLayout.

What is coordinator layout in framelayout?

At the Google I/O 2015, Google introduced Coordinator Layout to remove the difficulties of having more than one layouts in FrameLayout. Now, with the help of the CoordinatorLayout, the interaction between the views become very easy even in the case of animation.

What is the use case for coordinatorlayout?

CoordinatorLayout is a super-powered FrameLayout. CoordinatorLayout is intended for two primary use cases: As a top-level application decor or chrome layout As a container for a specific interaction with one or more child views

What is the difference between a relativelayout and a coordinatorlayout?

Rather, the root layout is a RelativeLayout, and the CoordinatorLayout is it’s only child. This is because we do not want the CoordinatorLayout’s children to slide out of view of the screen. Within the CoordinatorLayout, we have a NestedScrollView that contains a single LinearLayout. The LinearLayout, contains multiple CardViews.


2 Answers

What is a CoordinatorLayout? Don't let the fancy name fool you, it is nothing more than a FrameLayout on steroids

To best understand what a CoordinatorLayout is/does, you must first of all understand/bear in mind what it means to Coordinate.

If you Google the word

Coordinate

This is what you get:

enter image description here

I think these definitions helps to describe what a CoordinatorLayout does on its own and how the views within it behave.

A CoordinatorLayout (a ViewGroup) brings the different elements (child Views) of a (̶a̶ ̶c̶o̶m̶p̶l̶e̶x̶ ̶a̶c̶t̶i̶v̶i̶t̶y̶ ̶o̶r̶ ̶a̶n̶ ̶o̶r̶g̶a̶n̶i̶z̶a̶t̶i̶o̶n̶)̶ layout into a harmonious or efficient relationship:

With the help of a CoordinatorLayout, child views work together harmoniously to implement awesome behaviours such as

drags, swipes, flings, or any other gestures.

Views inside a CoordinatorLayout negotiate with others in order to work together effectively by specifying these Behaviors

A CoordinatorLayout is a super cool feature of Material Design that helps to create attractive and harmonized layouts.

All you have to do is wrap your child views inside the CoordinatorLayout.

<?xml version="1.0" encoding="utf-8"?> <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="com.byte64.coordinatorlayoutexample.ScollingActivity">   <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">      <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">            <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" />         <TableLayout             android:layout_width="match_parent"             android:layout_height="wrap_content"/>      </android.support.design.widget.CollapsingToolbarLayout> </android.support.design.widget.AppBarLayout>  <include layout="@layout/content_scolling" />  <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" />   </android.support.design.widget.CoordinatorLayout> 

and content_scrolling:

<?xml version="1.0" encoding="utf-8"?> <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="com.byte64.coordinatorlayoutexample.ScollingActivity"  tools:showIn="@layout/activity_scolling">   <TextView     android:layout_width="wrap_content"     android:layout_height="wrap_content"     android:layout_margin="@dimen/text_margin"     android:text="@string/large_text" />   </android.support.v4.widget.NestedScrollView> 

What this gives us is a layout that can be scrolled to collapse the Toolbar and hide the FloatingActionButton

Open:

enter image description here

Closed:

enter image description here

like image 146
Ojonugwa Jude Ochalifu Avatar answered Sep 27 '22 18:09

Ojonugwa Jude Ochalifu


Here it is you are looking for.

from docs

the Design library introduces CoordinatorLayout, a layout which provides an additional level of control over touch events between child views, something which many of the components in the Design library take advantage of.

https://android-developers.googleblog.com/2015/05/android-design-support-library.html

in this link you will see the demo videos of all above mentioned views.

hope this helps :)

like image 42
Qadir Hussain Avatar answered Sep 27 '22 19:09

Qadir Hussain