Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List color turns black while Scrolling

Tags:

android

I have one list activity which populates when I click on one tab, the problem is list colour turns black while scrolling it, even though i have not set any attributes to happen like that.. Any suggestions to avoid this problem? Thanks,

like image 356
user1065490 Avatar asked Dec 16 '11 07:12

user1065490


2 Answers

Add this to listView in the xml file:

android:cacheColorHint="#00000000"

or in Java code:

getListView().setCacheColorHint(0);
like image 182
Shailendra Singh Rajawat Avatar answered Oct 13 '22 14:10

Shailendra Singh Rajawat


I would suggest you to go through this article: ListView Backgrounds: An Optimization, this is must read article before customizing look of LitsView.

Taken from above document:

As mentioned before, ListView has a transparent/translucent background by default, and so all default widgets in the Android UI toolkit. This implies that when ListView redraws its children, it has to blend the children with the window's background. Once again, this requires costly readbacks from memory that are particularly painful during a scroll or a fling when drawing happens dozen of times per second.

To improve drawing performance during scrolling operations, the Android framework reuses the cache color hint. When this hint is set, the framework copies each child of the list in a Bitmap filled with the hint value (assuming that another optimization, called scrolling cache, is not turned off). ListView then blits these bitmaps directly on screen and because these bitmaps are known to be opaque, no blending is required. Also, since the default cache color hint is #191919, you get a dark background behind each item during a scroll.

To fix this issue, all you have to do is either disable the cache color hint optimization, if you use a non-solid color background, or set the hint to the appropriate solid color value. You can do this from code (see setCacheColorHint(int)) or preferably from XML, by using the android:cacheColorHint attribute. To disable the optimization, simply use the transparent color #00000000. The following screenshot shows a list with android:cacheColorHint="#00000000" set in the XML layout file

like image 36
Paresh Mayani Avatar answered Oct 13 '22 15:10

Paresh Mayani