Quantcast
Channel: The Crazy Programmer
Viewing all articles
Browse latest Browse all 761

Android LinearLayout Example

$
0
0

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>

 

Android LinearLayout Example

 

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>

 

Android LinearLayout Example

 

The code is self-explanatory, still if you are facing any difficulty to understand then you can ask by commenting below.

The post Android LinearLayout Example appeared first on The Crazy Programmer.


Viewing all articles
Browse latest Browse all 761

Trending Articles