Top-most and Bottom-most Horizontal Divider does not show up in ListView
Asked Answered
B

5

9

I am using a ListView. But the top-most and bottom-most horizontal bar does not show up. Why? I am using this:

android:divider="@android:drawable/divider_horizontal_bright"
Barytes answered 30/3, 2010 at 2:19 Comment(2)
Have you found a good solution for this problem? android:footerDividersEnabled doesn't work for me.Huddleston
umm, sorry never tried beyond that :(Barytes
V
9

Have you looked into setting android:headerDividersEnabled and android:footerDividersEnabled on the ListView?

Also, if you look for drawDivider in platform/frameworks/base/+/master/core/java/android/widger/ListView.java in the Android open source repository, you'll be able to find some more clues.

Vetavetch answered 30/3, 2010 at 8:33 Comment(2)
In a widget, it appears android:footerDividersEnabled and android:headerDividersEnabled does nothing. Still looking for other solutions.Eddington
I have three headers in my listview, the third header is supposed to be show/hide on run time. Is there any way to remove the third header's divider height (i.e set to 0) or any workaround?Inoculation
K
11

Add a dummy footer and header

listViewContato = (ListView) view.findViewById(R.id.listview_contatos);
listViewContato.addHeaderView(new View(getActivity()));
listViewContato.addFooterView(new View(getActivity()));
Kubetz answered 3/10, 2014 at 17:16 Comment(1)
this needs more love, it works! Footer as mentioned previously in Roman Nurik's comment thread, works right away, but header does require a header.Grapefruit
C
10

Here's how I implemented it... Bottom divider shows up after setting android:paddingBottom for the ListView. BUT in my case after setting android:paddingTop top and bottom dividers are not showing. I don't know why. So I added in my list_item_layout.xml the following code:

<View
    android:layout_width="match_parent"
    android:layout_height="1dip"
    android:background="?android:attr/listDivider" />

and in my adapter I just changing the visibility of this view:

View topDivider = v.findViewById(R.id.divider);

if (position == 0) {
    topDivider.setVisibility(View.VISIBLE);
} else {
    topDivider.setVisibility(View.GONE);
}

Hope this will helpfull to someone.

Changeful answered 11/1, 2012 at 12:38 Comment(0)
V
9

Have you looked into setting android:headerDividersEnabled and android:footerDividersEnabled on the ListView?

Also, if you look for drawDivider in platform/frameworks/base/+/master/core/java/android/widger/ListView.java in the Android open source repository, you'll be able to find some more clues.

Vetavetch answered 30/3, 2010 at 8:33 Comment(2)
In a widget, it appears android:footerDividersEnabled and android:headerDividersEnabled does nothing. Still looking for other solutions.Eddington
I have three headers in my listview, the third header is supposed to be show/hide on run time. Is there any way to remove the third header's divider height (i.e set to 0) or any workaround?Inoculation
A
2

I had the same problem with LibSlideMenu.

As android:headerDividersEnabled set to true did not show the header divider in the Sliding Menu, I solved it by changing slidemenu.xml (not slidemenu_listitem.xml) to

<LinearLayout ...>

    <LinearLayout ...>
    <ImageView ...>  (this is the header image on top of the menu)

    <View
    android:layout_width="250dip"
    android:layout_height="2dip"
    android:background="@drawable/divider" />

    <ListView ...> (this is the ListView for the MenuItems)
    </LinearLayout>


    <FrameLayout ...>
    </FrameLayout ...>
</LinearLayout>

This will add the divider manually.

Ambidexter answered 4/12, 2012 at 14:47 Comment(0)
B
0

First you'll have to enable the footerDividers in XML:

android:footerDividersEnabled="true"

Then simply add a dummy footer view like this

listview.addFooterView(new View(this), null, false);

You can do the same for header

Blairblaire answered 16/12, 2019 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.