Question

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"
Was it helpful?

Solution

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.

OTHER TIPS

Add a dummy footer and header

listViewContato = (ListView) view.findViewById(R.id.listview_contatos);
listViewContato.addHeaderView(new View(getActivity()));
listViewContato.addFooterView(new View(getActivity()));

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top