I have a ListView with a bunch of items inside it. How do I make the top and bottom items have a top margin of 10dp for top item and bottom margin of 10dp for bottom item? Now I
You can get space at the top and bottom of your ListView, inside the scrolling region, by using headers and footers. Here's a quick example:
Define your filler view, which I named header_footer.xml:
Now your onCreate
method looks like this, assuming you named your ListView listView
:
final LayoutInflater inflater =
(LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View headerFooter = inflater.inflate(R.layout.header_footer, null);
listView.addFooterView(headerFooter);
listView.addHeaderView(headerFooter);
And then set your adapter.