LinearLayout in activity_main.xml file
Following is the code for LinearLayout in xml file.
<?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.
- Horizontal list: One row, multiple columns.
- 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.
Contact Us