开发者

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

I wanted to change the divider height dynamically. From whatever I have searched it seems that it is possible through setting divider as part of each item in ListView. But I am not very clear with this.

So, can someone开发者_如何转开发 be more specific as how can one make the divider as part of item in ListView?


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.

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

You can make the divider as one of the items.

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

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

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

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜