LinearLayout in activity_main.xml file

Following is the code for LinearLayout in xml file.

activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/Main_View"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <TextView
        android:id="@+id/txtVw"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:layout_marginTop="20dp"
        android:paddingTop="20dp"
        android:text="Enter your name here:"
        android:textSize="24dp" />

    <EditText
        android:id="@+id/editText"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="16dp"
        android:hint="Name"
        android:inputType="text"/>

    <Button
        android:id="@+id/showInput"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:backgroundTint="@color/colorPrimary"
        android:text="show"
        android:textColor="@android:color/white" />



</LinearLayout>

Android LinearLayout in Kotlin

Android LinearLayout is a ViewGroup subclass, used to provide child View elements one by one either in a particular direction either horizontally or vertically based on the orientation property. We can specify the linear layout orientation using the android:orientation attribute.

All the child elements arranged one by one in multiple rows and multiple columns.

  1. Horizontal list: One row, multiple columns.
  2. Vertical list: One column, multiple rows.

Can illustrate the Horizontal and Vertical List with an Image.

In this article, we are going to discuss the declaration and implementation of LinearLayout.

Similar Reads

How to Declare LinearLayout in an XML file?

First of all, we should declare the LinearLayout in the layout file using the below code:...

LinearLayout in activity_main.xml file

Following is the code for LinearLayout in xml file....

MainActivity.kt file

When we have created layout, we need to load the XML layout resource from our activity onCreate() callback method and access the UI element form the XML using findViewById....

LinearLayout Output:

We can run the application using the Android Virtual Device(AVD) to get the output of the above code....

Contact Us