简体   繁体   中英

Android listview - Add a divider only at the end of the list

I'm creating a custom drawer view which has multiple listViews. To show this nicely to the user I want to separate these listViews with a divider.

I've managed to show the dividers between the items, and even get the last one to show a divider, but not just the last item.

I know I can toggle the dividers with

android:footerDividersEnabled="false"
android:headerDividersEnabled="false"

But that is not the desired effect (dividers between each listitem). I just need a line underneath the list.

My ListView XML at this point:

<ListView android:id="@+id/list_view_drawer"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="false"
    android:choiceMode="singleChoice"
    android:divider="@color/progress_gray"
    android:footerDividersEnabled="false"
    android:headerDividersEnabled="false"
    android:dividerHeight="1dp"
    android:background="#fff" />

Is there any way to achieve this effect?

Thanks in advance.

EDIT: I'm aware that I can put a view of 1dp height underneath the list. But I'm looking for an option within the list view. If that's not possible, which it's starting to look like. I'll go with that solution. Bit dirty in my opinion, but it can't be helped.

You could simply add a 1dp high View between your listviews.

</ListView>
<View
   android:layout_height="1dp"
   android:layout_width="match_parent"
   android:background="@android:color/red"
/>

In your drawer layout add:

<ListView android:id="@+id/list_view_drawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="false"
        android:choiceMode="singleChoice"
        android:background="#fff" />
<View
        android:layout_width="match_parent"
        android:layout_height="1dp"
        android:background="@color/progress_gray"/>

<ListView android:id="@+id/list_view_drawer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="false"
        android:choiceMode="singleChoice"
        android:background="#fff" />

You can add view a the end of list using addFooterView (View v) . More info here

And looks like you will need to do this from code.

For setting divider only at the last item of listview you can View or put horizontal line in imageview .

      <ImageView
        android:id="@+id/imageseprator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/strip" />

Or

     <View
        android:id="@+id/imageseprator"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/strip"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM