How to Add a horizontal line in Android Layout


There are many ways we can add a Horizontal line/rule in an Android Layout.xml file. One of the ways is to create a table row with background color and a height of say 1-2dp.

Horizontal line in Android Layout
Horizontal line in Android Layout
Source Code :

layout.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    tools:context=".MainActivity">


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit,
        sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
        android:padding="10dp"
        android:id="@+id/textView" />

    <TableRow
        android:id="@+id/hr"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#444"></TableRow>


    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit,
         sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."
        android:id="@+id/textView2" />


    <TableRow
        android:id="@+id/hr1"
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="#444"></TableRow>
</LinearLayout>
Output
Output