views:

252

answers:

1

Hi,

I have a listview in which there should be different divider height between different rows. So, how can we set the divider height dynamically?

Suppose, I have 10 rows and there should be a divider height of 5 between first 2 rows and then there should be a divider height of 1 between next 5 rows and so on.

Can someone let me know the way of doing this?

Regards Sunil

A: 

One way would be to make the dividers rows. Set them as not enabled in your isEnabled adapter method. I do that for section headers, but it is almost the same thing. Another way would be to manually lay out your whole list by implementing onLayout. If the dividers can be empty space, it might work to set top or bottom margins for the root view of your rows. In xml that would be:

    android:layout_marginTop='5px'

Otherwise, just make the dividers part of the rows.

drawnonward
I don't understand how can one include divider as part of the row. I have a background image for the row. If I include the divider as part of the row then that would be included within that image itself. I will like to have that image below the row image. How can one do this?
sunil
Each row can be a ViewGroup with any number of child views. One of those child views could be the divider image. It would mean using different types of rows for different size dividers.
drawnonward
Can you give me some example with show how to do it? Do you actually mean to place divider in the row xml file or have the different xml file for divider. Please let me know.
sunil
Place the divider in the row xml for rows that have a larger divider. You could have several different row layouts, or edit each row as it is created.
drawnonward
Yes, the list divider needs to be empty space i.e it will reflect the background color of the screen. Can you please let me know how to do this? I am really very clueless in this.
sunil