Here you will get Android LinearLayout example.
LinearLayout is a very basic and most commonly used layout in Android. It is used to align or arrange its children either horizontally or vertically. The horizontal or vertical orientation can be specified using android:orientation attribute. By default the orientation is horizontal.
Below I have shared an example for both orientations. I have used three buttons and arranged them in horizontal and vertical manner.
Android LinearLayout Example
Horizontal Orientation
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Apple"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Banana"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Orange"/> </LinearLayout>
Vertical Orientation
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Apple"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Banana"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Orange"/> </LinearLayout>
The code is self-explanatory, still if you are facing any difficulty to understand then you can ask by commenting below.