ListView颜色在屏幕底部更改

时间:2013-12-17 08:47:43

标签: android listview colors

我有一个奇怪的问题,在我的列表视图活动中,我根据某些变量设置了列表项的背景颜色。基本上,该项目将为白色或灰色,如果选中则为蓝色。

当我滚动列表(向下滑动)时,列表视图项目的颜色随着行越来越接近底部逐渐消失。在底部它失去了所有的原始颜色,我相信它现在是透明的。所以现在,两个不同颜色的行(白色和灰色)在底部看起来都一样。但是,蓝色的物品不会发生这种情况。

快速谷歌搜索让我添加

list.setVerticalFadingEdgeEnabled(false);

但这并没有对颜色变化产生影响。我在这里错过了什么吗?

如果需要,设置背景颜色的代码如下:

if (itemChecked.get(position)) {
                //If the row is selected, set blue
                row.setBackgroundColor(0x9934B5E4);
            } else if (!email.isRead()) {
                //If the email is unread, set white
                row.setBackgroundColor(Color.WHITE);
            } else {
                //Otherwise set grey.
                row.setBackgroundColor(0xd6d6d6);
            }

非常感谢任何见解,谢谢!

编辑:它看起来像什么。

屏幕顶部。 Top of the screen

屏幕下方 At the bottom of the screen

2 个答案:

答案 0 :(得分:1)

我最近看到了这个问题。给出的答案是,有一个默认的drawable应用于整个ListView背景的背景,该背景具有从灰色到白色的渐变。尝试给ListView一个纯色的背景,比如#ffffff。

所有类似的问题都说这是解决方案:

android:cacheColorHint="#000000"

答案 1 :(得分:0)

你可以试试这样的事情......

下面提到的将在任一行上放置不同的颜色.. 这段代码将放在getView()方法中..即ArrayAdapterClass中的方法

if(position%2 == 0)
        {
            rowView.setBackgroundColor(context.getResources().getColor(R.color.list_dark));
        }
        else
        {
            rowView.setBackgroundColor(context.getResources().getColor(R.color.list_light));
        }

就所有行而言,只需这样做..

rowView.setBackgroundColor(context.getResources().getColor(R.color.list_dark));

你可以在ArrayAdapterClass中实现它

相关问题