Why divider is not showing in the listview @android:id/list ?

Jimmy picture Jimmy · Mar 16, 2012 · Viewed 8.5k times · Source

I have a linear layout that contain the following listview :

<ListView
    android:id="@android:id/list"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:cacheColorHint="#00000000"
    android:divider="#FF0000"
    android:dividerHeight="4dp"
     />

and the layout is used by a ListActivity, the issue is that the following line in ListView xml doesn't take effect :

     android:divider="#FF0000"
    android:dividerHeight="4dp"

and the default divider is set. Do you why this happening and how to fix it?

Answer

Arpit Patel picture Arpit Patel · Mar 16, 2012

its an difference of the dp and px.

use this

android:dividerHeight="4px"

instead of

android:dividerHeight="4dp"

and use this also if you want

int[] colors = {0, 0xFFFF0000, 0}; // red for the example
myList.setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
myList.setDividerHeight(1);

you will get it..