Welcome back Developer , i hope you are fine , let us begin our third android lesson :
What Is an XML-Based Layout?
As the name suggests, an XML-based layout is a specification of widgets’ relationships to each
other—and to their containers encoded in XML format. Specifically,Android considers XML-based layouts to be resources, and as such layout files are stored in the res/layout directory inside your Android project.
Each XML file contains a tree of elements specifying a layout of widgets and their containers
that make up one view hierarchy. The attributes of the XML elements are properties, describing
how a widget should look or how a container should behave. For example, if a Button element
has an attribute value of android:textStyle = "bold", that means that the text appearing on
the face of the button should be rendered in a boldface font style.
Android’s SDK ships with a tool (aapt) which uses the layouts. This tool should be automatically invoked by your Android tool chain (e.g., Eclipse, Ant’s build.xml). Of particular importance to you as a developer is that aapt generates the R.java source file within your project, allowing you to access layouts and widgets within those layouts directly from your Java code.
OK, So What Does It Look Like?
Here is the Button code , converted into an XML layout file
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/button"
android:text=""
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
What’s with the @ Signs?
Many widgets and containers only need to appear in the XML layout file and do not need to be
referenced in your Java code. For example, a static label (TextView) frequently only needs to be
in the layout file to indicate where it should appear.
These sorts of elements in the XML file do not need to have the android:id attribute to give them a name.
Anything you do want to use in your Java source, though, needs an android:id.
The convention is to use @+id/... as the id value, where the ... represents your locally-
unique name for the widget in question.
In the XML layout example in the preceding section, @+id/button is the identifier for the Button widget.
• android:text indicates the initial text to be displayed on the button face (in this case, an
empty string)
• android:layout_width and android:layout_height tell Android to have the button’s
width and height fill the “parent”
for more details about XML-Based Layout : Please watch the videos.







