How to make divider part of each item in listview in android?

夙愿已清 提交于 2019-12-04 09:52:21

A way to do this would be to include the divider at the bottom of each row. Now you have to set the height of the divider view in your getView method in your listadapter depending of the item you are showing at the moment.

Nothing is better than explaining by picture. Here I found a screenshot from web. I made some mark on it.

This is what you want to achieve.

You can make the divider as one of the items.

Also, you can make the divider as a part of an item.

Neither of the 2 solutions uses real divider provided by ListView. It should be set 0 height. Sounds silly but it does effective.

You could set android:footerDividersEnabled to false and add dividers in your adapter.

In your ListActivity call:

ListView lv = getListView();
lv.setDivider(divider);

where divider is a Drawable object which you can define or write in your code as you need to.

You can also call:

lv.setDividerHeight(2);

To change the height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!