android - ListView 项目更改背景颜色

标签 android listview background scroll flicker

我的应用程序有一个奇怪的行为...A 有一个 ListView,其中奇数项有 #ffffff 背景,偶数项有 #f2f7f7,并且看起来像这样:

Activity start OR touching list (without release)

但是,当我开始滚动列表时,偶数项会稍微改变颜色,变成 #f7f7f7,如下所示:

When scrolling and after scroll release

有什么想法吗?如果您需要更多信息,请询问。我对这种行为感到困惑。

附加信息:

我在 getView() 方法中设置每个项目的背景颜色,如下所示:

protected final int[] colors = new int[] { R.drawable.states_list_odd, R.drawable.states_list_even };
...
// Alternates list items' background
int colorPos = position % colors.length;
convertView.setBackgroundResource(colors[colorPos]);

最佳答案

其实很简单。 android:scrollingCache="false" 解决了这个问题。

关于android - ListView 项目更改背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8681918/

相关文章:

android - 如何将线性布局 child 的高度设置为最高的 child 高度

java - Android ListView 与 LinkedHashMap - 滚动时列表乱序

Android ActionBar 选项卡 - ListFragment 问题

html - 改变 CSS 幻灯片的背景

Android Kotlin - 意外标记(使用 ';' 分隔同一行的表达式)

android studio ctrl + space 打开文档窗口

c# - 在 ListView 中选择下一项

css - 破折号:数字小部件背景颜色

css - 灯箱:使屏幕其余部分透明的问题

android - ListView 中的随机复选框选择未获取确切位置,显示索引超出范围异常