Introduction

Android has the following six types of layout in mobile applications:
  1. Linear Layout
  2. Relative Layout
  3. Table Layout
  4. Frame Layout

1. Linear Layout

First, create layout XML of the linear name.
Figure 1: Create Layout XML
Delete the default code in the XML file then open the graphical layout and drag a Linear Layout (Vertical ) or Linear Layout (Horizontal).
Graphical Layout
Figure 2: Graphical Layout
Drag Linear Layout
After dragging any one of them then go to the code in the XML file and see.
For LinearLayout (Vertical):
  1. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:layout_width="fill_parent"
  3. android:layout_height="fill_parent"
  4. android:orientation="vertical" >
  5. </LinearLayout>
  6. for Lu=inearLayout(Horizontal)
  7. <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  8. android:layout_width="fill_parent"
  9. android:layout_height="fill_parent" >
  10. </LinearLayout>
    So LinearLayout (Horizontal) is the default LinearLayout, but you can change the layout by editing the code:
    1. android:orientation="vertical"
    2. “Vertical” replace by Horizontal or delete this line then vertical convert into a horizontal layout

    2. Relative Layout

    The relative Layout is the default layout when we create activity.
    Relative is easy to use for adjusting the element in the layout.
    In a relative layout, every element arranges itself relative to other elements or a parent element.
    1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. xmlns:tools="http://schemas.android.com/tools"
    3. android:layout_width="match_parent"
    4. android:layout_height="match_parent"
    5. android:paddingBottom="@dimen/activity_vertical_margin"
    6. android:paddingLeft="@dimen/activity_horizontal_margin"
    7. android:paddingRight="@dimen/activity_horizontal_margin"
    8. android:paddingTop="@dimen/activity_vertical_margin"
    9. tools:context="com.example.layouts.RelativeMainActivity" >
    10. </RelativeLayout>
    Example
    Relative Layout
    Figure 3: Relative Layout
    Relative Layout code
    Figure 4: Relative Layout code

    3. Table Layout

    The Table Layout works as a HTML table in Android. In the Table Layout you can divide the layout into rows and columns. It is also easy to understand.
    Table Layout
    Figure 5: Table Layout
    1. <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    2. android:layout_width="wrap_content"
    3. android:layout_height="wrap_content"
    4. >
    5. <TableRow
    6. android:id="@+id/tableRow1"
    7. android:layout_width="fill_parent"
    8. android:layout_height="wrap_content"
    9. android:gravity="center_horizontal" >
    10. <TextView
    11. android:id="@+id/textView1"
    12. android:layout_width="wrap_content"
    13. android:layout_height="wrap_content"
    14. android:text="Row1Col1"
    15. android:textAppearance="?android:attr/textAppearanceLarge"
    16. android:background="#b0b0b0"
    17. android:textColor="#0000bb"
    18. android:layout_weight="1" />
    19. <TextView
    20. android:id="@+id/textView8"
    21. android:layout_width="wrap_content"
    22. android:layout_height="wrap_content"
    23. android:text="Row1Col2"
    24. android:textAppearance="?android:attr/textAppearanceLarge"
    25. android:background="#b0b0b0"
    26. android:textColor="#00bb00"
    27. android:layout_weight="1"/>
    28. </TableRow>
    29. <TableRow
    30. android:id="@+id/tableRow2"
    31. android:layout_width="fill_parent"
    32. android:layout_height="wrap_content"
    33. android:gravity="center_horizontal"
    34. >
    35. <TextView
    36. android:id="@+id/textView2"
    37. android:layout_width="wrap_content"
    38. android:layout_height="wrap_content"
    39. android:text="Row2Col1"
    40. android:textAppearance="?android:attr/textAppearanceLarge"
    41. android:background="#b0b0b0"
    42. android:textColor="#bb0000"
    43. android:layout_weight="1"/>
    44. <TextView
    45. android:id="@+id/textView3"
    46. android:layout_width="match_parent"
    47. android:layout_height="wrap_content"
    48. android:background="#b0b0b0"
    49. android:text="Row2Col2"
    50. android:textAppearance="?android:attr/textAppearanceLarge"
    51. android:textColor="#0000b0"
    52. android:layout_weight="1" />
    53. <TextView
    54. android:id="@+id/textView4"
    55. android:layout_width="wrap_content"
    56. android:layout_height="wrap_content"
    57. android:text="Row2Col3"
    58. android:textAppearance="?android:attr/textAppearanceLarge"
    59. android:background="#b0b0b0"
    60. android:textColor="#00b00b"
    61. android:layout_weight="1"
    62. />
    63. </TableRow>
    64. <TableRow
    65. android:id="@+id/tableRow3"
    66. android:layout_width="fill_parent"
    67. android:layout_height="wrap_content"
    68. android:gravity="center_horizontal" >
    69. <TextView
    70. android:id="@+id/textView7"
    71. android:layout_width="wrap_content"
    72. android:layout_height="wrap_content"
    73. android:text="Row3Col1"
    74. android:textAppearance="?android:attr/textAppearanceLarge"
    75. android:background="#b0b0b0"
    76. android:textColor="#00bb00"
    77. android:layout_weight="1"/>
    78. </TableRow>
    79. </TableLayout>

      4. Frame Layout

      The Frame Layout is a flexible layout for changing the height and width of elements. It gives us the facility to overlap elements with each other, such as Text on an image.
      Frame Layout
      Figure 6: Frame Layout
      1. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      2. android:layout_width="fill_parent"
      3. android:layout_height="fill_parent" >
      4. <ImageView
      5. android:id="@+id/imageView1"
      6. android:layout_width="match_parent"
      7. android:layout_height="262dp"
      8. android:src="@drawable/ic_launcher" />
      9. <TextView
      10. android:id="@+id/textView1"
      11. android:layout_width="match_parent"
      12. android:layout_height="226dp"
      13. android:gravity="center_vertical|center_horizontal"
      14. android:text="Frame Layout"
      15. android:textAppearance="?android:attr/textAppearanceLarge"
      16. android:textSize="35sp" />
      17. </FrameLayout>