Layout

Understand how to work with the Android layout in this lesson.

Layout concept

A layout defines the structure of the user interface. Layouts are built via views and view groups.

Views, also sometimes called “widgets,” represent interactable components such as:

  • TextView - component to render text
  • EditText - input field component where user can type text
  • Button - clickable text component with background

ViewGroups, sometimes also called “layouts,” represent invisible containers that define the position of its children on the screen. While Android SDK contains a number of view groups, which still can be used, Google recently released a new view group called ConstraintLayout.

This layout comes as a separate library and uses constraints to position views on the screen. ConstraintLayout is more complicated than Android SDK view groups, but it has a rich visual editor to help build the user interface and in most cases has better performance.

While we can create a layout in Java code, it’s easier to build a layout in the XML file and then inflate (bind) this layout to a specific activity.

Building layout

Let’s try to create a layout with the “Hello World” text in the middle of the screen.

First, create a new ...