Layouts in Android
A layout defines the structure for a user interface in an app, such as in an activity. All element in a layout is build using a hierarchy of view and view group object. A View usually draws something the user can see and interact with. Whereas a ViewGroup is an invisible container that defines the layout structure for View and other ViewGroup objects.
The View objects are usually called "widgets" and can be one of many subclasses, such as Button or TextView. The ViewGroup objects are usually called "layouts" can be one of many types that provide a different layout structure, such as LinearLayoutor ConstraintLayout.
Let's see each of the layout types that are used in android.
Linear Layout
LinearLayout is the most basic type of Layout. It helps us to place the view in a linear fashion.
This type of Layout enforces you to put your controls in a linear direction, either horizontally or vertically.
Relative Layout
RelativeLayout enforces to display elements in relations to each other. You can specify that, for instance, one UI element can be said to be placed on the left of another element, or on the bottom of another etc. Each UI element can also be positioned according to the layout’s borders.
RelativeLayout is very powerful. Consider that for building mobile apps’ interfaces these can be run on multiple devices with different screens’ resolutions. RelativeLayout allows (if properly built, of course) to adjust your set of controls easily to almost every type of screen.
Table Layout
As its name suggests, TableLayout allows to group of elements into rows and columns. May be useful when displaying some statistics or reports.
Grid View
GridView displays items in a two-dimensional grid. The list can be easily scrolled. This type of Layout is often used on screens displaying photos or similar sets of “blocks” to click.
Tab Layout
Tabbed layouts allow introducing tabs in our Android application. Then, a single Activity may contain several tabs and the user can easily switch between them. On each tab, you can use a different type of Layout.
List View
ListView allows displaying a list of items. It may be used in multiple places, from shortlists of menu options to a long list of emails or news feed. It allows us to easily and quickly present a list of items.
Happy Reading!!!