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

前端 未结 5 648
情话喂你
情话喂你 2021-02-08 21:49

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_horiz         


        
相关标签:
5条回答
  • 2021-02-08 22:02

    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.

    0 讨论(0)
  • 2021-02-08 22:07

    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.

    0 讨论(0)
  • 2021-02-08 22:07

    Add a dummy footer and header

    listViewContato = (ListView) view.findViewById(R.id.listview_contatos);
    listViewContato.addHeaderView(new View(getActivity()));
    listViewContato.addFooterView(new View(getActivity()));
    
    0 讨论(0)
  • 2021-02-08 22:14

    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

    0 讨论(0)
  • 2021-02-08 22:20

    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.

    0 讨论(0)
提交回复
热议问题