‫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 view group objects.
‫A view usually draws something the user can see and interact with, such as text, view button, edit
‫text, and so, whereas a view group is an invisible container that defines the layout structure for
‫view and other view group 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 view group 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 view.
‫Group objects.
‫Once you've defined the root element, you can add additional layout objects or widgets as 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 linearlayout, relativelayout, constraintlayout, framelayout, and so on.
‫Layout attributes.
‫Every view and view group 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 this 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 view group 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 used 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.