The most commonly used layout classes in android are:
- FrameLayout – designed to display a stack of child View controls. Multiple view controls can be added to this layout. This can be used to show multiple controls within the same screen space.
- LinearLayout – designed to display child View controls in a single row or column. This is a very handy layout method for creating forms.
- RelativeLayout – designed to display child View controls in relation to each other. For instance, you can set a control to be positioned “above” or “below” or “to the left of” or “to the right of” another control, referred to by its unique identifier. You can also align child View controls relative to the parent edges.
-
TableLayout – designed to organize child View controls into rows and columns. Individual View controls are added within each row of the table using a TableRow layout View (which is basically a horizontally oriented LinearLayout) for each row of the table.
Defining an XML Layout Resource
The most convenient and maintainable way to design application user interfaces is by creating XML layout resources. XML layout resources must be stored in the /res/layout project directory (or, in the case of alternative resources, in a specially named sub-directory).
The following is a simple XML layout resource, a template with a LinearLayout containing a TextView and an ImageView, defined in XML:
<?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”
android:gravity=”center”>
<TextView
android:layout_width=”fill_parent”
android:id=”@+id/PhotoLabel”
android:layout_height=”wrap_content”
android:text=”@string/my_text_label”
android:gravity=”center_horizontal”
android:textSize=”20dp” />
<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/matterhorn”
android:adjustViewBounds=”true”
android:scaleType=”fitXY”
android:maxHeight=”250dp”
android:maxWidth=”250dp”
android:id=”@+id/Photo” />
</LinearLayout>



