A brief overview of Layout XML in Android. Part 1

While fashionable and modern are testing jetpack composite in new projects, we will talk about the good old XML markup.

Literally a couple of sentences about each layoutto get a general idea of ​​their application. For those who want more details – attached additional links.

The article is intended for those who are just starting to develop on Androidbut perhaps more experienced developers will learn useful information for themselves.

1. FrameLayout

  • The simplest type of markup.

  • All children of the FrameLayout are anchored to the top left corner of the screen.

In markup FrameLayout you cannot specify a different location for a child object. Subsequent child objects view will simply be drawn on top of the previous components, partially or completely shading them if the object on top is opaque, so the only child for FrameLayout usually stretched to the size of the parent container and has the following attributes:


More: FrameLayout – Alexander Klimov

2. CoordinatorLayout

  • Is the heir to the standard FrameLayout.

  • Main feature CoordinatorLayout — their default behaviorby using Behaviors you can control the child view.

main attraction CoordinatorLayout is its ability to coordinate animations and view transitions within the XML file itself.

CoordinatorLayout – learntutorials.net
CoordinatorLayout – temofeev.ru


  • Available in two options – Horizontal And Vertical.

  • Aligns all child objects in the same direction, either vertically or horizontally.

The direction is specified using the orientation attribute android:orientation:


More: LinearLayout – Alexander Klimov

4. TableLayout

  • Displays items in a table format, in rows and columns.

  • Does not display border lines for rows, columns, or cells.

  • The number of cells in different lines may differ.

  • When forming a row, some cells can be left empty.

To form interface strings, you must use the object TableRowwhich must be a child of the container TableLayout. Each component TableRow defines a single row in a table. Row cells are containers for other objects. You can put another one in a cell TableLayout or LinearLayout. This type of markup is convenient to use, for example, when creating logic games such as Sudoku, Tic-Tac-Toe, etc.

TableLayout – java-online.ru
TableLayout – Alexander Klimov

5. GridLayout

  • For any component, you can specify a row and a column, and in this place of the table it will be placed.

  • Components can span multiple table cells.

  • Several components can be placed in one cell.

You can’t use the weight attribute in this markup because it won’t work on child views. GridLayout. Use attribute layout_gravity.

GridLayout – metanit.com
GridLayout – Alexander Klimov

6. SwipeRefreshLayout

  • Works on the principle of “swipe down to perform some function (for example, update)”.

SwipeRefreshLayout – javadevblog.com
SwipeRefreshLayout – Alexander Klimov

7. RelativeLayout

RelativeLayout – metanit.com
RelativeLayout – Alexander Klimov

A bonus for those who like to not only read articles, but also watch videos:

Video Fundamentals of XML markup of the user interface – Roman Andrushchenko
Video FrameLayout, LinearLayout, GridLayout – Roman Andrushchenko
Video Brief overview of basic UI components – Roman Andrushchenko

Hmm, where is ConstraintLayout? Have you forgotten about the coolest layout?

The point is that the ConstraintLayout there are so many possibilities and “chips” that it is more logical to devote a separate article to it, and not try to cram everything into the first part.

Similarly with MotionLayout – it makes sense to talk about animation in the subsequent parts of the review article.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *