为什么我的可绘制ListView分隔符消失了?

时间:2011-12-21 08:58:52

标签: android

慢慢滚动ListView时,我发现红色分隔符从顶部消失。我该如何解决?

public class UITestActivity extends ListActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ListView listView = this.getListView();
    listView.setBackgroundColor(android.graphics.Color.WHITE);
    listView.setCacheColorHint(android.graphics.Color.TRANSPARENT);
    listView.setAdapter(new ArrayAdapter<String>(this,
            android.R.layout.simple_expandable_list_item_1, getData()));
    listView.setDivider(new ColorDrawable(android.graphics.Color.RED));
    listView.setDividerHeight(50);
    listView.setFadingEdgeLength(0);
}

private List<String> getData() {
    List<String> data = new ArrayList<String>();
    for (int i = 0; i < 20; i++) {
        data.add("data" + i);
    }
    return data;
}
}

1 个答案:

答案 0 :(得分:1)

只需设置标题分隔符参数:listView.setHeaderDividersEnabled(true);