Linear Layout Tutorial


      Using LinearLayout all layout elements are aligned alongside, horizontally or vertically. In this view group all its children are placed one after another, which means that there can only be one child in each row, regardless of its width.

      Layout's orientation is set using android:orientation attribute. Here are two examples of horizontal and vertical LinearLayout:



1. Vertical LinearLayout



Android LinearLayout
Vertical LinearLayout

         
       As you can see I am also using android:layout_gravity attribute to centre our buttons horizontally.

2. Horizontal LinearLayout


Horizontal LinearLayout
Horizontal LinearLayout

         I have changed the value of android:layout_width to "wrap_content" because if I would have left it set to 250dp our buttons wouldn't have fit into the screen and would have looked like this: 
Horizontal LinearLayout gone wrong:)


Source Code

References: