Previous | Home | Next |
View or ViewGroup object are the root elements each layout file. XML is very helpful for design UI layouts. You could create web pages in HTML. We can divide the layout in 2 ways.
- Android provides widgets and layouts class that are used to create the layout.
- You can instantiate layout elements at runtime that means programmatically.
You could declare your application's default layouts in XML, including the screen elements that will appear in them and their properties. You could then add code in your application that would modify the state of the screen objects, including those declared in XML, at run time. The layout opt tool find out inefficiencies or other problems. You can change or modify your source code and recompile. In general, the XML vocabulary for declaring UI elements closely follows the structure and naming of the classes and methods, where element names correspond to class names and attribute names correspond to methods.
However, note that not all vocabulary is identical. you can guess what XML attribute corresponds to a class method, or guess what class corresponds to a given xml element. In some cases, there are slight naming differences. For example, the EditText element has a text attribute that corresponds to EditText.setText().
Attributes : There are many type attributes in XML. View object have some type attributes eg. textSize attribute but every attributes is inherited by any View objects.id attributeed is the the root View class.
- ID : ID attributes uniquely identify the View within the tree. This is an XML attribute common to all View objects and you will use it very often. The
- Layout Parameters : XML layout attributes named layout_something define layout parameters for the View that are appropriate for the ViewGroup in which it resides.
"android:id="@+id/my_button"
Previous | Home | Next |