What is layout?
When ever we talk about layouts in android the first thing to keep in mind is that all they’re all subclasses of ViewGroup — a View that supports adding child Views (commonly referred to as children).
As you might expect, one of the main responsibilities of a ViewGroup is laying out those children: picking how large each View is (the ‘measure’ phase) and placing the Views within the ViewGroup (the ‘layout’ phase).
Common Android Layouts
below there is a quick summary about the different types of layouts that are used in android , this shot introduction about the layout will help you to choose a layout for your project.
LinearLayout children are placed in a single row or column (depending on if its android:orientation is horizontal or vertical).
However, even with that single focus, it still has a layout_weight attribute, which allows a child to expand its size to fill the remaining space — useful if you have a few wrap_content elements and a few others that need as much space as possible.
FrameLayout acts quite differently compared to LinearLayout: all children of FrameLayout are drawn as a stack — overlapping or not. The only control on positioning is the attribute — the child can be pushed towards a side or centered within the FrameLayout.
RelativeLayout is not nearly as simple as the previous two: a look at RelativeLayout.LayoutParams shows a large number of attributes all focused around positioning children relative to the edges or center of RelativeLayout (similar to FrameLayout in fact), but also relative to one another — say, one child layout_below another child.
In simple and easy words the children in RelativeLayout can be positioned according to there parent (by layout_ParentAlign….) asa well as according to other children (by layout_toBelowOf Or layout_toRightOf ).
TableLayout organizes content into rows and columns. TableLayout works in the same way HTML table layouts work.
But, before using TableLayout one must keep in mind that that are used to create tables that have data in a small amount. if the data is to be displayed in the tabular list form then you must use GridView.
CoordinatorLayout, part of the Android Design Support Library, is a subclass of FrameLayout and therefore inherits its use of layout_gravity to position children, but also includes the concept of a Behavior.
Attaching a Behavior to a view either by using the @DefaultBehavior annotation on the class, using the layout_behavior attribute, or using setBehavior() allows that Behavior to intercept just about everything before the underlying View: measurement, layout, nested scrolling, touch events, changes to specified dependent Views, and window insets.
So that’s all about the basic concepts about the layouts that are used in android UI designing. you can create awesome screen layout by using these layouts just keep in mind about the parent and child relation as every layout use different ways to position its children. Next time you are struggling with a particular layout, consider taking a step back and seeing if there’s an easier way to do thing by using a different layout or it’s just you have to look at the way you are managing the layout children .