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](https://code2care.org/pages/add-horizontal-line-in-android-layout/images/Horizontal line in Android Layout.png)
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](https://code2care.org/pages/add-horizontal-line-in-android-layout/images/Output.png)
Output
More Posts related to Android,
- Increase Android Emulator Timeout time
- Android : Remove ListView Separator/divider programmatically or using xml property
- Error : Invalid key hash.The key hash does not match any stored key hashes
- How to Change Android Toast Position?
- Android Alert Dialog with Checkboxes example
- Android : No Launcher activity found! Error
- Android Development: Spinners with Example
- Failed to sync Gradle project Error:failed to find target android-23
- INSTALL_FAILED_INSUFFICIENT_STORAGE Android Error
- Disable Fading Edges Scroll Effect Android Views
- How to create Toast messages in Android?
- Channel 50 SMSes received every few minutes Android Phones
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Create Custom Android AlertDialog
- How To Disable Landscape Mode in Android Application
- Android Development - How to switch between two Activities
- incorrect line ending: found carriage return (\r) without corresponding newline (\n)
- Generate Facebook Android SDK keyhash using java code
- Android Error Generating Final Archive - Debug Certificate Expired
- 21 Useful Android Emulator Short-cut Keyboard Keys
- Android RatingBar Example
- 11 Weeks of Android Online Sessions-15-Jun-to-28-Aug-2020
- Download interrupted: Unknown Host dl-ssl.google.com Error Android SDK Manager
- fill_parent vs match_parent vs wrap_content
- Android : Connection with adb was interrupted 0 attempts have been made to reconnect
More Posts:
- Fix: Spring Boot REST HTTP Status 415 - Unsupported Media Type Error - Java
- Opening mac Terminal - MacOS
- URL Encode cURL HTTP GET\POST Data with Examples - cURL
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows - Git
- What is the Default Admin user and Password for Jenkins - Linux
- Must Know Homebrew Commands for Mac/Linux Users - MacOS
- Setting up Spring Boot 3 + Maven + MySQL + JDBC Example - Java
- How to hide lines in Notepad++ - NotepadPlusPlus