Android Drawing Separator/Divider Line in Layout? Android Drawing Separator/Divider Line in Layout? android android

Android Drawing Separator/Divider Line in Layout?


I usually use this code to add horizontal line:

<View    android:layout_width="match_parent"    android:layout_height="1dp"    android:background="@android:color/darker_gray"/>

To add vertical separator, switch the layout_width and layout_height values


To improve on the answers provided by Alex Kucherenko and Dan Dar3

I added this to my styles:

<style name="Divider">    <item name="android:layout_width">match_parent</item>    <item name="android:layout_height">1dp</item>    <item name="android:background">?android:attr/listDivider</item></style>

Then in my layouts is less code and simpler to read.

<View style="@style/Divider"/>


Add this in your layout where you want the divider (modify the attributes to fit your need):

<ImageView    xmlns:android="http://schemas.android.com/apk/res/android"    android:src="@android:drawable/divider_horizontal_dark"    android:layout_width="fill_parent"    android:layout_height="wrap_content"    android:scaleType="fitXY"    android:paddingLeft="5dp"    android:paddingRight="5dp"    android:paddingBottom="2dp"    android:paddingTop="2dp" />