2

I have a ListView which must fill whole free space in a parent layout. I want to remove the last divider and this is my code:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/listView"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_width="fill_parent"
        android:choiceMode="singleChoice"
        android:listSelector="@drawable/popup_table_row"
        android:footerDividersEnabled="false"
        android:headerDividersEnabled="false" />

    <Button
        android:id="@+id/cancelbutton"
        android:layout_height="wrap_content"
        android:layout_width="fill_parent"
        android:text="@string/cancel"
        style="@style/ButtonTextBold"
        android:background="@drawable/blue_button" />

</LinearLayout>

The android:headerDividersEnabled="false" does nothing. The last divider is not removed. I tried to implement the layout using the RelativeLayout and setting the height of the listView to fill_parent, but it also doesn't help.

smb
  • 834
  • 1
  • 8
  • 17
  • set divider color to transparent. – Amrut Apr 15 '14 at 12:07
  • I don't want to set divider's color to transparent, because I need dividers between elements. I just don't need the bottom divider. – smb Apr 15 '14 at 12:08
  • try setting the height of the listView to fill_parent and remove that weight. Also are you using listfragment? if yes then try listFragment.getListView().setFooterDividersEnabled(false); – Amrut Apr 15 '14 at 12:12
  • If I'll set `fill_parent` in `LinearLayout` for the first element, my other elements will not be visible. No, I don't use `ListFragment`. – smb Apr 15 '14 at 12:17
  • don't use the list-view divider. take a view in your list-view item and handle it's visibility depending on position in getview. – Amrut Apr 15 '14 at 12:40
  • I think this isn't the best solution, but I also think it will work... Thank you. I will try it if I'll not find another one. – smb Apr 15 '14 at 12:49
  • Answered: http://stackoverflow.com/questions/4961999/remove-the-bottom-divider-of-an-android-listview – keno Mar 25 '17 at 07:25

2 Answers2

1

use list view property android:divider="@null"

Jaspreet Chhabra
  • 1,431
  • 15
  • 23
0

Try This

<ListView
    android:id="@+id/listView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignLeft="@+id/ibtn_regstepone_fbconnect"
    android:layout_below="@+id/btn_regstepone_alreadymember"
    android:layout_marginTop="59dp" 
    android:divider="@null">
Umer Kiani
  • 3,783
  • 5
  • 36
  • 63
  • I can't set android:divider to `null`, because I need dividers. I just don't need the last (bottom) divider. – smb Apr 15 '14 at 12:26
  • try this http://stackoverflow.com/questions/14199274/separator-divider-after-last-item-of-listview – Umer Kiani Apr 15 '14 at 12:35
  • Thank you for the answer. I wrote above that I tried to implement the layout using `RelativeLayout` and setting height to `fill_parent`, but it didn't help. My layout is inflated in `DialogFragment`, maybe this is the reason, I don't know. And don't realize how to remove this bottom divider. – smb Apr 15 '14 at 12:40