Remove the bottom divider of an android ListView

后端 未结 5 868
鱼传尺愫
鱼传尺愫 2020-12-02 10:04

I have a fixed height ListView. It has divider between list items, but it also displays dividers after the last list item.

Is there a way to not display

相关标签:
5条回答
  • 2020-12-02 10:39

    It seems below line does not work on lollypop device.

    listView.setFooterDividersEnabled(false);
    

    So need to use this below code to remove divider after last item in the list.

    listView.setOverscrollFooter(new ColorDrawable(Color.TRANSPARENT));
    
    0 讨论(0)
  • 2020-12-02 10:46

    As @ScootrNova said, this seems to be behaving differently (a.k.a buggy) in android 4.4.x (I don't know exactly when the problem is introduced)

    This is related to the specific case of using using padding + clipToPadding="false" - in 4.4.x the footer is drawn outside of the view but clips to padding reveals it.

    The solution I used was to set the footer over-scroll (android:overScrollFooter) to transparent which somehow works...

    My final solution (note that android:footerDividersEnabled is kept for back-compatibility):

    <ListView
        android:id="@android:id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/activity_horizontal_margin"
        android:divider="@color/divider"
        android:dividerHeight="1px"
        android:clipToPadding="false"
        android:scrollbarStyle="outsideInset"
        android:overScrollFooter="@android:color/transparent"
        android:footerDividersEnabled="false"
        />
    

    tested on a HTC One X running 4.1.1, a Nexus 5 running 4.4.4 and a Samsung Galaxy S5 running 4.4.2 (thanks to @Dallas187). Seems to be working Lollipop too. (thanks to commenters!)

    0 讨论(0)
  • 2020-12-02 10:54

    Just add android:footerDividersEnabled="false" to your ListView description

    0 讨论(0)
  • 2020-12-02 11:01

    Use background = @android:color/transparent. Works perfectly. You can still use the background of your row layout

    0 讨论(0)
  • 2020-12-02 11:03

    If you want to do this by code it's:

    listView.setFooterDividersEnabled(false);
    

    and if you're using a ListFragment you can get the listview by:

    listFragment.getListView().setFooterDividersEnabled(false);
    

    Only commented because this comes up as #1 in google

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