How to set divider between columns in tablelayout?

brig picture brig · Apr 9, 2012 · Viewed 38.6k times · Source

I want to create a table with column dividers. I want to divide my columns with a vertical bar image. To achieve this I have used "android:divider="@drawable/abc" but its not working. Below is my xml file for same:

 <TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" 
   android:stretchColumns="*"
    android:padding="5dip"
android:divider="@drawable/tracking_green"
>
<TableRow  >

<TextView
    android:id="@+id/retaileritem1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:text="xxxxxxx" />

<TextView
    android:id="@+id/retaileritem2"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:text="xxxxxxx" />

<ImageView
    android:id="@+id/retailerimage1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1"
    android:src="@drawable/tracking_green" />

</TableRow>

Answer

Sonny Ng picture Sonny Ng · Apr 5, 2013

Add android:showDividers="middle"

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="horizontal" 
  android:stretchColumns="*"
  android:padding="5dip"
  android:divider="@drawable/tracking_green"
  android:showDividers="middle"
>