When I create a simple layout with only a ListView in it, there is no separator displayed after the last item, which looks a bit ugly.
I've come with a hack that works around this problem. Since the last separator is displayed only if another view follows the list view, it is possible to make that second view invisible by setting its layout_height
to 0dp
.
It's still a hack, but it makes to last divider look consistent with the other, so it's better that trying to manually create a horizontal line with trying to guess the right colour and dimensions.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/invisible"
android:layout_alignParentTop="true" />
<View
android:id="@+id/invisible"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true" />
</RelativeLayout>
Add an empty view to top (and/or bottom) to create a divider on top (or bottom)
myList.addHeaderView(new View(context));
myList.addFooterView(new View(context));
The answer is very simple: you should change android:layout_height="wrap_content"
to android:layout_height="match_parent"
in your ListView
.
You can probably guess why this happens.
I do something similar to what @Natix describes, but instead of messing with the containing layout of the list I simply add the empty view as a footer on the list via ListView.addFooterView()
Have you tried this one ?
android:footerDividersEnabled="true"
if not try this out
<View
android:background="#00ff00"
android:layout_width="fill_parent"
android:layout_height="3dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/YOUR_LIST_ID" />
It seems somewhat different when your listview is displayed if you code it like that. But even you can follow this too.
First define a style named Line
<style name="Line">
<item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">2px</item>
<item name="android:background">@color/white</item>
</style>
// In the above style you can change the height of the line as per your requirement.
Wherever you want to use the above line, you can declare it like this in your xml file.
<LinearLayout
android:orientation = "vertical"
.......................
............................>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<View
style="@style/Line"/>
</LinearLayout>
The above code creates a line under your listview. The above code is most useful when you wanna use it in various places in your project. Or if want at only one place, you can do it like this.
<LinearLayout
android:orientation = "vertical"
.......................
............................>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<View
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="#20b2aa" />
</LinearLayout>
Hope this helps. BTW The reason is vague and even once I did search for this and I followed this way which I explained above.