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

4

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?

Rectory answered 16/3, 2012 at 16:20 Comment(1)
i check it and it works for me and red color divider,,,,Shaynashayne
T
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..

Tomkin answered 16/3, 2012 at 16:25 Comment(3)
I choose dp to be display density independent but i also give px a try and didn't work.Rectory
see this article you will get some idea danroundhill.com/2009/12/18/working-with-the-android-listviewTomkin
Nice gradient divider. :o)Tavern
A
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.

Abate answered 4/4, 2014 at 5:55 Comment(0)
R
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);
Rectory answered 16/3, 2012 at 17:9 Comment(0)
M
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

Maui answered 23/4, 2015 at 7:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.