Welcome back.
In this video, we'll learn about layouts.
A layout refers to the XML files that define the structure and appearance of user interface elements
for an Android app.
Layouts play a crucial role in designing the user interface of an Android application.
They allow you to arrange and position various UI components such as buttons, text views, images and
more within the user interface of the application.
Layouts serve as blueprints for how the user interface should be organized, and they help in achieving
a consistent and visually appealing design across different devices and screen sizes.
All elements in the layout are built using a hierarchy of view and viewgroup objects.
A view usually draws something the user can see and interact with, such as text, view, button, edit,
text and so on.
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 text,
view or image and so on.
The viewgroup objects are usually called layouts can be one of many types that provide a different layout
structure such as linear layout, relative layout, constraint, layout, and so on.
Let's move on.
How to create the layouts.
Each layout must contain exactly one root element, which must be a view or viewgroup objects.
Once you've defined the root element, you can add additional layout objects or widgets as a child elements
to gradually build a view hierarchy that defines your layout.
For example, this is a linear layout that contains text view and the button.
This is the text view.
This is the button, this is the opening tag and where we define the attributes of this linear layout.
And this is the closing tag of the linear layout.
So again, guys, it's very important to note each layout file must contain exactly one root element
which is linearly out, relatively out, Constraintlayout, framelayout and so on.
Layout attributes every view and Viewgroup object supports their own variety of XML attributes.
Some attributes are specific to the view object itself.
For example, text view supports the text size attribute, but these attributes are also inherited by
any view objects that may extend this class.
Some are common to all view objects because they are inherited from the root view class objects like
the ID attribute id attribute.
Any view object may have an integer ID associated with it to uniquely identify the view within the tree
and we worked with the ID attribute before.
Now let's move to the layout parameters.
XML layout attributes named layout underscore something Define layout parameters for the view that are
appropriate for the viewgroup in which it resides.
For example, layout underscore width and layout underscore height.
All view groups include a width and height parameters and each view is required to define them.
Many layout params also include optional margins and borders.
We saw in the previous examples and videos we use the Wrapcontent and Matchparent wrap content tells
your view to size itself to the dimensions required by its content, while Matchparent tells your view
to become as big as its parent view group will allow.
One last note to mention is the layout position.
The geometry of a view is that of a rectangle.
A view has a location expressed as a pair of left and top coordinates and two dimensions expressed as
width and height.
The unit for location and dimensions is the pixel.