如何动态地更改列表视图的分隔高度?视图、高度、动态、列表

2023-09-04 23:45:34 作者:三世温柔

我有一个列表视图,其中应该有不同的隔高度 不同行之间。那么,怎样才能设置分隔高度 动态?

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

假设,我有10行,应该有5分的高度 之间的第一2行,然后应该有1除法高度 下一个5行之间等。

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?

推荐答案

一个方法是使分隔行。它们设置为你的的IsEnabled 适配器方法未启用。我这样做的节头,但它几乎是同样的事情。另一种方式是手工奠定了你的整个列表通过实施onLayout。如果分频器可以是空的空间,它可能工作设置顶部或底部边距为您排根视图。在XML中,这将是:

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.