 Hello everyone. So in this video, we are going to see layouts in Android. I am Mr. D. P. Gandmal from Valchand Institute of Technology, Sulapur. I am an assistant professor in computer science and engineering department. So today in this session, we are going to see layouts in Android. So this is one of the important concepts in Android. So what we are going to see the learning outcome in this particular video will be the students will be able to identify various types of layout in Android. And students will be able to design various types of layout in Android. So we are going to study various types of layouts that are present in Android. It is very important because various screen sizes we have. Likewise, now layouts. What is layout? Layout defines the structure for a user interface in your app such as in an activity. Now what is activity? Activity is something we see on a mobile that is a screen. So whatever we see on a mobile particular screen is an activity. Now for example in this particular mobile we can see this window. Right. So this is an activity. Whenever you open an app that particular screen whichever we see that is an activity. Now here, how layouts are defined in Android? Layouts are defined with the help of a tree structure. We have view here. We have view group. So view group and view we have here. So we will study more into it what is view and what is view group. So let us see a view group is an invisible container that defines the layout. So layouts are a variety of types. We will study what are the different types. So they are defined into variety of types. Now all these types are used with the help of view group which is an invisible container. So we usually draw something the user can see and interact with. So this layout why layouts are important is it is not an ideal component. It is an active component. UI is an ideal component whereas activity is an interactive component. So in activity we have buttons. So when you click on a button some action is going to happen. This is nothing but interactive way of working with your particular buttons. Now this is a hierarchy of view group. So view group how these layouts are structured. They are structured with help of some classes. The classes are view group. In view group we have many views. So every view group can be have a child of views. Likewise here view group is having two views. Another view group can have another view group likely is a nested call. So here a view group is having three views and here view group is having a view group. This is a nested way of storing the layouts. So a linear layout can have a grid layout inside it. A grid layout inside it can have a linear layout. So likewise the layouts can be arranged. So this video this particular diagram is important to understand the structure of a layout. Now declaring layouts. How you can declare a layout. There are two ways to declare a layout. One using an XML file we have dot layout dot XML file main activity dot XML file. So all your layouts are defined inside XML files. So this declare UI elements in an XML. So Android provides a straightforward XML vocabulary that corresponds to view classes. So all your buttons radio button checkboxes any component can be added into XML file. So that particular XML file is one way of putting your components on your layout. Another way is you can change the layout at runtime. This is an important feature given by Android. Like when I click on a button I want a calculator to be opened. So that calculator is again a grid view. Likewise here layout at runtime can be done with help of a button click or some kind of action listener. Okay I hope you are following. Next this is an important slide. How we will define a layout. So here we are first dealing with linear layout. Let's take an example of linear layout. So what how linear layout XML tag is written. This is a linear layout and inside this linear layout we have some attributes. These are important attributes while you are writing an XML code. So attributes here is first attribute is android, second attribute is layout width, third attribute is layout height and orientation. These four attributes are important in linear layout. Any layout you take these four attributes are must. So here android, so we will give the standard library of android. This android will refer. Then we have layout width. So match parent is a parameter that is used for layout width and layout height. We have two types match parent and wrap parent. So we will study about match parent and wrap parent later. So match parent is nothing but matching that particular component with the layout size. So whatever layout size you are defining your button will fit into that particular it will match the x axis and y axis. So your components will be stored vertically. Either you want a layout to be in a vertical fashion or in a horizontal fashion that can be done by setting this orientation. So you can either have vertical or horizontal. Then we have text view. Here we have taken two components text view and button. So you can have many number of components inside that particular layout. Okay. I hope you are understood this particular slide. This slide is important. You can just copy paste it and check the working of this XML file. Next, here we will, this will be a simple question for you people. Various attributes required in layout for XML code. What are the different attributes required in a layout? You pause the video and you can rewind the video and give answer for this particular question. So the answer for this is Android, layout width, layout height and orientation. These are the four important attributes we have seen. We can see that slide, particular slide here. Android, layout width and layout height and orientation. These are the four important attributes in linear layout. Okay. Then moving ahead. Loading an XML resource. So XML resources are again, so we need to put it into XML file. XML file is different and Java file is different. So whatever, how we are going to refer to that XML file, that XML file can be referred through Java code because Java is going to execute, not XML file. So when you execute a Java file, here we have on create. In on create method, you will be writing super dot on create. This line will come by default when you start your program. Second line, here this line is important, set content view. R is a resource folder. Dot layout dot main layout. So inside layout, we have created one XML file with title main layout. So you will be referring to this main layout or any other layout file if you have, if you have given layout one or my layout. So this particular file name will change. Rest r dot layout will be same. Is that clear? So public void on create activity dot on create. So on create will be called as soon as your application gets launched. When you click on a particular button and that application gets launched, as soon as that application gets launched, the particular method called a set content view gets called. That's why using this set content view, XML file will get started. This XML file will execute and the application will be loaded onto the screen. Now while creating any component, the component is having an ID associated with it. This ID is very important. So either Android provide this ID or you can give your own ID. So when you drag and drop from a window, when I drag and drop a particular button onto my XML file, this at plus ID slash my button will come. This plus is nothing but appending to an existing component. If suppose there are three buttons already and I am trying to add a fourth button, this plus will add this particular button as a fourth button after three buttons. Okay, so this plus is important here. So slash my button. Whatever button name is there, you can change this my button name in strings dot XML file. Then we have either you can references directly at Android. This is not preferable but so you can do it at Android ID. So you are adding that particular button as an ID with empty component. Now creating views and references. We have seen this code initially in an XML file. So button when you're adding a button, that button will have an ID at plus. As I mentioned now, this will be a plus slash my button. So this my button can be changed. Every button is having width and height and it is having a text associated with it. So width and height can be wrap content and this thing. So similarly, my button will have this button is particularly access using find view by ID, r.id.my button. Layouts, this is a structure which we have already seen. You can pause it and see it in detail. They're at common layouts type. Similarly, we have linear layout. Only that particular tag will change. We have seen linear layout, relative layout, relative layout. In linear layout, all the components will be arranged in a vertical or horizontal manner. In relative layout, the component can be arranged anywhere. It can be either to left, to the right, to the above or below. Web view is a standard format. You can refer it. Then we have list view. It will come as a list, drop down list. List one, list two, list three. It will be a list view. You cannot alter it. And a grid view. So according to the concept, you can select the layout. In grid view, we can go for a calculator. Mostly calculator is used in grid view. So you can use it. So just that particular tag name will change. Other rest all components will be same. So these are some of the references which I have used. The standard references I suggest you to go to these websites and this book. It is very helpful. Thank you.