Most Android application user interfaces are defined using specially formatted XML
files called layouts. Layout resource files are included in the /res/layout directory.
You compile layout files into your application as you would any other resources.
Here is an example of a layout resource file:
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
</LinearLayout>
You might recognize this layout: It is the default layout, called main.xml, created
with any new Android application. This layout file describes the user interface of the only activity within the application. It contains a LinearLayout control that is used as a container for all other user interface controls—in this case, a single TextView control. The main.xml layout file also references another resource: the string resource called @string/hello, which is defined in the strings.xml resource file.
There are two ways to format layout resources. The simplest way is to use the layout resource editor in Eclipse to design and preview layout files. You can also edit the XML layout files directly.
files called layouts. Layout resource files are included in the /res/layout directory.
You compile layout files into your application as you would any other resources.
Here is an example of a layout resource file:
<?xml version=”1.0” encoding=”utf-8”?>
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android”
android:orientation=”vertical”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”>
<TextView
android:layout_width=”fill_parent”
android:layout_height=”wrap_content”
android:text=”@string/hello” />
</LinearLayout>
You might recognize this layout: It is the default layout, called main.xml, created
with any new Android application. This layout file describes the user interface of the only activity within the application. It contains a LinearLayout control that is used as a container for all other user interface controls—in this case, a single TextView control. The main.xml layout file also references another resource: the string resource called @string/hello, which is defined in the strings.xml resource file.
There are two ways to format layout resources. The simplest way is to use the layout resource editor in Eclipse to design and preview layout files. You can also edit the XML layout files directly.