What is Android XML layout file

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
so hi my name is Mahesh basically I'm working as a senior software engineer on Java and Anna dinner technologies so in my previous videos I explained what is android why android and what is the directory structure of android and all the things so in this session I'll explain you for every single screen for every single screen in Android we need two files one is an Java file and one XML file for every single screen in Android we need two files on Java file and one XML file so Java file is called as activity Java file is called as activity and XML file is called as layout for every single screen you need two files on Java file and one XML file Java file is called as activity XML file is called as layout so first I will explain you the layout I mean XML part then we will discuss the Java part okay so XML Android XML file is called as layout okay so first I'll create on sample project alkyd on sample project and I'll see what XML file consists and all the things okay so create a new project let us take file new Android application project specify the project name let us take a urine sample project hollower [Music] so let us take my project name is hallo the guy is a project name so next so the time of creating the project it is creating two files on Java file and one XML file so Java file is called as activity the Java file name is main activity XML file is called as layout XML file amis activity underscore main so click on finish so by default when you create on project and create on project it is going to create and sample activity I mean on sample screen for you so for this sample screen we need two files on Java file and one XML file so in my last videos I explained the directory structure of Android application so Java file is going to locate inside the SRC folder this is a Java file main activity dot java XML file is going to locate inside the layout folder the layout folder which is available in a resource folder layout folder this is the XML file activity underscore main dot XML so select here activity underscore main dot XML you will get the XML code you will get the XML code so first we will discuss about what is win by XML why XML and all the things okay for every single screen we need two files one Java file and one XML file XML file is called as layout XML file is called as layout so for few minutes we'll discuss about what is in by XML why XML what XML consists and all the things okay XML xml is termed as extensible markup language XML is termed as what extensible markup language select HTML HTML is also called as H HTML is termed as hypertext much luggage here XML is called as extensible markup language my question is what is meant by a markup language so markup language means enclosing the data enclosing the data within tax is called as a markup language let us take if we take on HTML file or XML file for example I am creating an HTML file or a snake HTML body let us take if you want to h1 steak third gap [Music] slash body slash HTML this is on sample HTML file next XML file just I want to maintain some students details let's take students [Music] this is on sample XML file and this is on sample HTML file so HTML is termed as hypertext markup language XML is termed as extensible markup language markup language in the sense enclosing the data within tags is called as a markup language enclosing the data within tags is called as a markup language so xml is termed as extensible markup language so what are the users with XML what are the users with XML the first great advantage of XML is XML is called as in the operable technology XML is called as interoperable technology or it is called as interoperable format XML is unless interoperable technology or interoperable format meaning interoperability means which is a platform independent technology independent and language independent XML is termed as extensible markup language the first great advantage of XML is it's a interoperable format meaning which is a platform independent technology independent and language independent the complete web services concept the complete web series concept internally working on XML if there is no XML there is no concept of web services meaning the first great advantage of XML is XML is used to transfer the data between multiple technologies if you want to transfer the data from one technology to another technology use XML so that is the first one XML is called as a interoperable format there is a first-grade advantage of XML next XML by using XML XML is used as textual data base XML is used as what XML is used as a textual database let us take imagine I started one company the startup company so company in the sense definitely will be the requirement of holding some data to hold the data in market some database servers are they liked or killed MySQL MySQL server different database servers are there but I don't have that much capacity to purchase on database server but in my application I want to maintain some data so if you want to maintain some data so one of the option is XML so XML is used as a textual database also so in our applications also XML is one of the textual database if you want to maintain your data so one of the storage method is XML the first advantage is XML is used XML is used as a textual database XML is a interoperable format which is used to transfer the data over the multiple technologies and XML is used as [Music] XML is used as deployment descriptor silastic if you have a knowledge on some of web technologies like servlets so after developing your web application to deploy your web application into the server we need to write one we need to write one document so that document is nothing but web dot XML if you dollop any application by using servlets or struts after developing the application you need to write one document if you want to deploy your application to the server you need to write on document the document is nothing but a web dot XML in case of dotnet so after developing your web application to deploy your application into servers I like is you need to write one document call web - config dot XML for web - config dot XML my question is why they preferred why they preferred XML why not a some other format meaning here internally the web servers are developed by using internally the web servers are developed by using some native technologies like CR C++ by using some native components like CR C++ if you if you write the if you write the deployment descriptors in another doc another format this you cannot read that format in the CN C++ but same thing if you write same thing if you write in XML XML can be read by any programming language you can read the XML file in C programming language you can read the XML file in Java you can read the XML file in dotnet so that's why XML is called as interoperable format which is a platform independent technology independent and language independence so XML is used as textual data base XML is interoperable format which is used to transfer the data between multiple technologies XML is used for XML is used as a deployment descriptor these are the advantages of XML apart from these advantages apart from these advantages so what are the rules to write an XML file what are the rules to write an XML file if you observe for writing this XML file so which maintains some students details for writing this XML file I followed some rules I followed some rules the first rule for creating XML file is every XML file have a root element the for Rule two create an XML file XML file is every XML file have a a root element so here the root element for this XML file is students the root element for this XML file is students the first rule to create an XML file is every XML file have a root element so in this XML file students by students is a root element that is a first rule next every element must be properly nested every element must be properly necessary if you observe all the opening tags are occlusive every element must be properly nested there is a second rule every XML file have a root element in our example the root is students and xml element must be properly nested here all the elements are properly nested next should not contain spaces between the tag names should not contain spaces between the tag names our acronym for example if you want to specify an elastic first name first XML will not allow these spaces XML will not allow the spaces between the diagrams there is a third rule should not contain spaces between the eliminate should not start with a number should not start with a number these are some of the basic rules to write an XML file these are the basic rules to write an XML file every XML XML element must be properly nested every XML file have a root element should not start with a number should not contain spaces between the tags these are the basic rules to write an XML file next apart from these here the student name is Mahesh the student name is on Mahesh so I want to provide a restriction to the user I want to provide a restriction to the user the minimum length of this is the minimum of this name is maximum 6 characters I want to provide a restriction to the user the minimum length is how many characters 6 characters here in the S ID take only a number type of data from the user don't accept a string type of data a character type only accept and member if that s ID tag Ulrika once again the xml basic rules are every XML file have a root element should not contain spaces in the element names every element must be properly nested should not start with and number these are the basic rules to write an XML file apart from that basic rules here I want to provide my own restrictions to the XML file the minimum length of this name is 6 characters I want to take only a number type of data from the user I don't want to take a character type of data from the user if you want to provide your own restrictions to the user if you want to provide your own restrictions to the user use a DTD or accessory DTD Easter Mass document type definition XS D is termed as XML schema definition DTD is termed as document type definition XS d is termed as xml schema definition so DTD is the old approach so now the latest one is exactly by using accessory you can provide more restrictions to the XML file so why I am discussing all these things because remember this by using XS d we can provide our own restrictions to the XML file why am i why explain this much story in the Android every XML file every XML file is going to follow one xst every XML file is going to follow one existing remember is point so here we create on sample project in that sample project it is created two files on Java file and one XML file so first I will give some points about XML XML is termed as extensible markup xml is termed as extensible markup language the advantages of XML is the advantages of XML is the first advantage of XML is XML is XML is used to transfer the data XML is used to transfer the data between multiple technologies XML is used to transfer the data between multiple technologies these are first is the first advantage of XML XML is used to transfer the data between multiple technologies next XML is used as textual database if you want to maintain some data in your application XML is used as what it takes to a database XML is used as textual database next XML is used as deployment descriptors if you want to deploy your application XML is used as a deployment descriptor xml is used as deployment descriptor there are other lot of advantages are there these are the major advantages of xml next so what are the rules to create an XML file the first rule to create an XML file is every XML file have a root element every XML file have a root element next every XML element must be properly nested every XML element every XML element must be properly nested is a second rule every XML file have a root element every XML element must be properly nested should not start should not start with a number should not start with a number and should not contain should not contain any spaces should not contain any spaces between the tags these are some of the basic rules to create an XML file every XML file have a root element every XML element must be properly nested should not start with the number or should not contain spaces between the tags these are some of the basic rules to create an XML file apart from these how to create how to create your own restrictions to the XML file how to create your own restrictions to the XML file if you want to create your own restrictions to the XML file there is a concept called a DTD DTD is termed as a document type definition a document type definition xst is termed as accessory is termed as XML schema definition DTD is the old approach now the latest applications are using Excel stick in Android every XML file is going to follow one xst so we will open our project we create on a project we created on project or project Mimi's or project name is activity underscore main dot XML open the project so what is the first lis about the first one what is it me related layout we'll discuss so this second line if you observe this second line xmlns : Android is equal to some URL xmlns : Android is equal to there is some URL why you need to specify that URL if you observe here already layout underscore width the tag was already specified so if I try to give the same attribute once again Android : Android : layout underscore width if I try to give the same attribute once again observe [Music] if I try to you the same attribute once again it is showing an error t showing an error so put the cursor here read the error attribute Android : layout underscore width was already specified for an element relative layout my question is this is just a normal XML file how this XML file knows this restriction how this XML file knows this restriction inside this relative layout enter only this layout under school with the maximum how many times only one time where this discretion is variable where this restriction is available this restriction is available in 1 X s D so this statement is going to follow this statement is going to specify the follows on existing so this is the XS d location this is the XS d location for this XS the location we created one shortcut name we created a shortcut name the shortcut name is nothing but Android we get it on shortcut name what is the shortcut name Android in the interviews in the interviews the interviewer will ask a question can we replace this Android maximum people will give the answer we cannot replace but we can replace because it is just a shortcut name for the specified URL it is just a shortcut name for them for this complete URL you can give any name let us take what I will do is I will rename this Android with a Linnaean this under it might it can give any name because xmlns is termed as it's a namespace it's just namespace in the sense a shortcut name for the specified URL but you have to start every tag you have to start every tag in place of Android with my okay so in Android remember one thing in Android every XML file is following one xst the first statement is the location of xst this XML file is following one x SD this is the location of that x SD file next we'll discuss what is this layout underscore width height and everything so before this there are some different UI groups are there is an Android just my intention is just my requirement is my requirement is on top of surface on top of device surface just I want to print on message I want to print on message welcome to Turkish or my requirement is I want to print this message on the mobile surface welcome to the gas off this is a requirement for this requirement in android some UI components are there like textview by using text view you can place a text on surface but before that fun you need to understand directly we cannot place a UI components if you want to place the UI components on surface first of all you need to create the UI group first of all you need to create a UI group there are lists of UI groups solid let us take linear layout one is linear layout a relative layout linear layout relative layout table layout like like lot of UI groups are there better UI groups some list of UI components are one is textview x 2 is another UI component edit text Spiner autocomplete x2 you like the number of UI components are there there are number of UI components are available in Android so remember one thing if you want to place the Y components on surface if you want to place the UI components on surface before placing the UI components on surface first of all you need to create one UI crew you need to create one UI group then only you can place the UI components let us take the first UI group is linear layout what is the first way group linear layout is one of the UI group so linear layout is linear layout is one of the UI group linear layout is one other UI group so by using linear layout by using linear layout we can arrange by using linear layout we can arrange the UI components we can arrange the UI components either in a vertical manner we can arrange the UI components either in a vertical manner or in it a horizontal manner so linear layout is one of the UI group by using linear layout we can create the UI components either in a vertical manner or horizontal manner and one more important point one after another one one after another linear layout is one of the UI group by using linear layout we can arrange the UI components either in a vertical manner or in a horizontal manner one after another meaning let us take this is your email this is a device surface for example if you want to create on button here if you want to create on button at the end of the screen that is not possible with linear load that is possible first of all you need to fill this gap you need to fill all these gap so you need to fill the gap up to this then only you can place a button here then only can place unbuttoned here so that is linear load by using linear layout you can arrange the UI components either in a vertical manner or a horizontal manner one after another directly if you want to place on you a component here that is not possible with that is not possible with linear layout first of all you need to fill all these gap then only can play some component here remember that one so in my XML file in my XML file in place of linear layout I am using a linear layout we discuss right every element must be properly nested if you open with linear layout you have to close it linear layout so in order to specify this XML tools so we are clear about the first first line the first line which is 1 X is the location in Android every XML file is following 1 X s T the first line is 1 X is the location what is the second one the layout underscore width and layout underscore height for this width and height for this width and height maximum we can pass first the signal to create the syntax the syntax to create the linear layout is linear layout so give the width and height and write : layout underscore width layout underscore width and Android : layout underscore height so give the width and height of the UI component so give one more parameter you need to specify the orientation let us take Android : orientation is equal to let us take on giving a vertical linear layout so this is on sample this is on sample a linear layout file here you need to write the logic to create the UI components the first what is the first one the width and for every Y component and ey group we need to specify the width and height for this width and height maximum you can pass five possible parameters the five possible parameters are the first one is fill parent fill parent next one is wrap content mash parent you can specify in pixels or you can specify in deepest for this awake group and ey component you can specify five possible parameters the five possible parameters are you can use either filled parent wrap content mash parent a pixels and deepest the first parameter fill parent fill parent in the sense if we specify fill parent and mash parent both are same fill parent and match parent both are same actually and before Android 2.2 there is no match parent this mash parent is introduced from after Android 2.2 Worsham okay the both meaning is same for free parent and match parent both meaning is same to occupy the complete screen if you take our example okay boss you want to present one a text on surface what is the text welcome to the Gus oft to present this component first of all you need to create one UI group we created on linear layout if we specify the width is equal to fill parent it is going to occupy the complete screen width from zero position to from zero position to up to the end of the screen from zero patient up to the end of the screen if we specify either a filled parent or mash parent what is another one wrap content rock content in sense it is going to occupy it is going to occupy the screen up to the content it is going to occupy the screen up to the content the name itself is describing a rap content up to the content if you specify filled parent or match parent it is going to occupy the complete screen width if we specify width is equal to fill parent it is going to occupy the complete screen width if we specify height is equal to fill parent it is going to occupy the complete screen height if we specify rap content which is going to occupy up to up to the content of the screen the fourth one is directly can specify pixels so let us take on top of the screen on top of the screen I want to occupy I want to occupy just one hundred 100 pixels directly can specify with this 100 pixels if you want to occupy height is hundred pixels you can specify Heidi's hundred pixels you can specify any pixels one more thing what is the last one you can specify in and DPS the five parameters are fill parent match parent wrap content pixels and deepest so deep if you want occupy 100 pixels hundred pixels specify 100 DP by hundred DB Android is preferred to use DPS than pixels because if you take here let us take the resolution of this device is the resolution of these each device is 320 by 480 what is the resolution 320 by 480 resolution if we specify pixels if we specify in pixels if you deploy the same application if you deploy this same application in 1 0 24 by 768 if you deploy this same application in 1 0 24 by 768 resolution if we specify in pixels it is going to be fixed 100 pixels you can deploy in 480 by 800 or 8 and a bit 1 1 0 24 1 0 2 0 768 if we deploy in any resolution of the device there is a fixed width and height that is 100 pixels and hundred pixels if we specify in DPS okay this is 320 by 480 resolution the width and height is 100 pixels by 100 pixels automatically it will calculate the than height automatically it will increase the width and height if we specify a if we specify if we specify the deep is open or XML file this is I created one sample layout group the layout group is linear layout I specified the width is match parent and Heidi's match parent meaning it is going to occupy the complete screen width on screen height and for the UI GRU you need to specify orientation meaning you want to arrange the UI components in a vertical manner or you want to arrange items in a horizontal manner you need to specify let us take I am specifying Android colon orientation so let us take vertical so if you specify particle meaning we are going to arrange the UI components one after another okay so we crater on UI group i I decided I want to arrange the UI components one after another so that's why I taken here what is the way group linear layout next what is your intention we want to present one welcome to trigger soft message on surface our intention is present one welcome to the resort message on surface this is the final requirement so first we create an only UI group a one minute we created only anyway just my intention is only we created on you a group that's it if you want to present any text on this UI if you want to present any text on this one in Android there is a component call text view what is the component text view so text view is text view is one of the UI component in Android text view is one of the UI component in Android which is used to display which is used to display text on surface text we is another way component Android which is used to display text on surface the syntax to create the text V component is textview for every way component these are the two properties the width and height are the two properties give the width and height for the textview component but if you specify I specified wrap content by wrap content meaning it is going to occupy up to the content next which text you want to present specify that one by using Android colon text so what is the text just I want to present a welcome to the soft on console will goes out welcome to the gas off message on browser close so by using text view component we can present text on surface so write this in in your XML file x2 you specify and write : a layout underscore width we will for this one is a wrap content next Android : leave it underscore height for this and also specify a wrap content next specify the text which takes you want to present on the surface let us take on to present welcome to do the soft message on on the surface sub Z this is XML file if you want to see the preview if you want to see the preview how it looks like on surface select graphical layout so once if you select the graphical layout it will show you how it prints how it prints the message on cancer welcome to Delta so this is the output it will show you the preview on console so this is how to create the XML file for every single screen we need two files one Java file and one XML file XML file is called as layout this is our sample XML layout file we created manually we created manually the XML file otherwise if you want to create any UI component or UI group directly can use a drag and drop also if you want to present on text on surface directly can use the drag and drop for example if you want to create on button let us take drag and drop will create a button for you you can use tag and drop but internally internally when you create anyway component internally it will generate one XML file so that's why first I created on you a component manually by using XML code otherwise you can you can use a drag under of support also okay next and this is the XML file next so XML file is called as and right layout okay so for every single screen any one XML file and one Java file XML file is completed so in our next session I mean in the next video I will explain you the Java part what Java part transitioned all the things I'll explain you in the next next tutorial thank you
Info
Channel: Durga Software Solutions
Views: 67,942
Rating: undefined out of 5
Keywords: durga, durgasoft, interview, questions, android, What is Android XML layout file
Id: xyGvzPVZdVk
Channel Id: undefined
Length: 37min 45sec (2265 seconds)
Published: Mon Jul 14 2014
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.