ListView solves the problem of black background when sliding, while listview slides
ListView. setCacheColorHint (Color. TRANSPARENT); // solves the black background problem when sliding.
Black background when listView slides
The reason is that ListView has a cache color mechanism, so we can solve this problem by setting the cache color to transparent.
A. Set by layout attributes (directly defined in the attributes of ListView)
Android: cacheColorHint = "#00000000 ″
B. Set it directly in the code
ListView. setCacheColorHint (Color. TRANSPARENT );
In this way, the black problem can be solved.
Why is my listview background black optimized?
To use android: cacheColorHint = "@ null" and android: listSelector = "@ null", listview is a commonly used display control to remove the background color, the Default background is the same transparent color as the system window. if you add a background image or background color to the ListView, The listView will be black when scrolling, because, when scrolling, when the view in the list is re-painted, the system's default transparent color is still used. The color value is # FF191919. to change this situation, you only need to call setCacheColorHint (0) of listView ), the color value is set to 0, or the Android: cacheColorHint = "#00000000" attribute of listView in the xml file. When you scroll, there will be no background color when you repaint the View. Android: listSelector = "#00000000" after the above settings, the ListView does not have any symptom when you click item. android: listSelector = "@ null" cannot be implemented. When customizing listview, if you do not use android: cacheColorHint = "#00000000", a black background of the selected space will appear, compromising the overall aesthetics.
The background of ListView becomes black when scrolling. How can this problem be solved?
When the finger scrolls up or down in the ListView, the background of ListViewItem turns black, because the background is optimized to improve the performance during scrolling. To improve the scrolling performance, the Android framework introduces the CacheColorHint attribute in the ListView. If the value is not 0, it indicates that the ListView is drawn on a monochrome opaque background. By default, this value is #191919, that is, the black background color value in the black topic, in this way, when the ListView is rolled, this value is used to draw the background of the ListView.
There are two solutions:
1. in xml, the new attribute in ListView is android: cacheColorHint = "#00000000 ″
2. In a Java file, set the following attributes for ListView: listview. setCacheColorHint (Color. TRANSPARENT );
From: www.anbiji.com/index.php/archives/109