1

I have a list view and I want to add a bottom border to each list item so it acts as a separating line between all the cells.

This is my list view right now.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:descendantFocusability="blocksDescendants"
    android:background="#FFFFFF"
    >

....
.....
</LinearLayout>
Anthony
  • 33,838
  • 42
  • 169
  • 278

2 Answers2

3
 <ListView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:divider="@color/red"
    android:dividerHeight="1px">
 </ListView>

and color value is inside colors.xml or strings.xml:

<color name="red">#FF0000</color>

P.S. I am using px on purpose check here

Community
  • 1
  • 1
Shereef Marzouk
  • 3,282
  • 7
  • 41
  • 64
0

Create a drawable like this , and set it to the list item background. This will set border only for layout bottom.

 <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:top="-1dp" android:right="-1dp" android:left="-1dp">
    <shape >
        <stroke
            android:width="1dp"
            android:color="#FFFF" />
    </shape>
 </item>
</layer-list>

or you can also try to set a divider for ListView

  android:divider="#FFFF"
  android:dividerHeight="1dp"
Libin
  • 16,967
  • 7
  • 61
  • 83