5

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?

Jimmy
  • 10,427
  • 18
  • 67
  • 122

4 Answers4

5

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..

Arpit Patel
  • 1,561
  • 13
  • 23
4

For me this is working perfectly:

 <ListView
     android:id="@+id/listHomeScreen"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:cacheColorHint="#000"
     android:divider="#7F7F7F"
     android:dividerHeight="1dip"
     android:listSelector="@android:color/transparent" >
</ListView>

Ensure we are not overriding android:dividerHeight or divider color.

Roberto Alarcon
  • 1,430
  • 2
  • 18
  • 32
Vinod Joshi
  • 7,696
  • 1
  • 50
  • 51
1

There is bug in Android Lollipop 5.0 if you have overridden setEnabled() then this happens. Check ot this question for more info ListView divider not showing in Android 5

Community
  • 1
  • 1
Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
1

Its resolved now. the issue is before i decide to make the list in xml i had this code in my listActivity to add divider which was overriding the xml :

int[] colors = { 0xA8A8A8A8, 0xFFFFFFFF, 0xA8A8A8A8 };
getListView().setDivider(new GradientDrawable(Orientation.RIGHT_LEFT, colors));
getListView().setDividerHeight(1);
Jimmy
  • 10,427
  • 18
  • 67
  • 122