How to make the separation part of each item in a list in android?

I would like to dynamically change the height of the separator . From everything I've been looking for, it seems like it's possible by setting a separator as part of each item in a ListView . But I do not really understand this.

So, maybe someone more specific, how can you make a divider as part of an element in a ListView ?

+4
source share
4 answers

The way to do this is to include a separator at the bottom of each line. Now you have to set the height of the separator view in getView in your list depending on the item you are currently displaying,

0
source

Nothing better than explaining the picture. Here I found a screenshot from the Internet. I made some comments.

This is what you want to achieve. enter image description here

You can make a separator as one of the elements. enter image description here

In addition, you can make the separator part of an element. enter image description here

Neither of the two solutions uses the real divider provided by ListView . The height should be set to 0. Sounds silly, but it is effective.

0
source

You can set android: footerDividersEnabled to false and add separators to your adapter.

-1
source

In your ListActivity call:

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

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

You can also call:

 lv.setDividerHeight(2); 

To change the height

-1
source

Source: https://habr.com/ru/post/1313146/


All Articles