Add margin above top ListView item (and below last) in Android

后端 未结 5 1759
情书的邮戳
情书的邮戳 2020-12-07 08:06

This is a pretty fine question about the layout of items in a ListView in Android.

I have an activity with a title bar at the top and a ListView taking up the rest

5条回答
  •  无人及你
    2020-12-07 08:26

    My solution using a ListFragment, based on the solutions by @Jakobud and @greg7gkb.

    ListView listView = getListView();
    listView.setDivider(null);
    listView.setDividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height));
    listView.setHeaderDividersEnabled(true);
    listView.setFooterDividersEnabled(true);
    View padding = new View(getActivity());
    listView.addHeaderView(padding);
    listView.addFooterView(padding);
    

提交回复
热议问题