Why does my list change color while scrolling on some phones?
As we all know, developing an android app means supporting a lot of os versions depending on what is your choice of api levels.
A lot of times, while setting custom background colors for Android’s listview, developers can be faced with a weird issue wherein while scrolling the listview background changes unexpectedly, and lead to inconsistent behaviour across devices.
Digging deeper into it, there is a lot going behind the scenes than it seems. Android list view by default has a transparent background and in order to match it with the background color set, it will have to blend each of its child with the background upon redraw. This is a very costly operation during a scroll gesture since scrolling causes multiple redraws per second, and blending each would require reading back stuff from memory. In order not to incur such expenses, the listView reuses the cacheColorHint set on the listview, if the android:scrollingCache property is enabled for the listview (which it is by default). The cacheColorHint is set to the system default, which could vary from the color you used for the background! This causes the background color to be different when scrolling.
Hmm, so how to fix this? Two options: either disable the cacheColorHint by setting it to transparent(#00000000) or simply set it to the background color you chose.
Hope this helps!
Cheers








