How to beautify the background of ListView in android

Source: Internet
Author: User

The ListView control is often used on the android interface. In the UI design, many people want to beautify the background of the control. Changing the background is actually very simple. In the layout file, add the code android: background = "@ drawable/bg" to the ListView control, and bg is the name of the background image. However, after this is done, the background is changed, but when you drag it, or click the blank position of the list, you will find that the ListItem is black, damaging the overall effect. As shown in:
 

 
Why? Because the background of ListItem in ListView is transparent by default, and the background of ListView is fixed, the background should be mixed with the display content of each Item during scrolling, in order to optimize this process, android: cacheColorHint is used, and the default color value is #191919 in the black topic, so the picture just now appears. Half of them are black.
If you only want to change the background color, you just need to specify the android: cacheColorHint as the desired color value.
If you want to use an image as the background, you only need to set the android: cacheColorHint value to transparent, that is, set the value to #00000000. In this way, the beautification will sacrifice some efficiency.
After beautification:





From Peking University-Google Android lab

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.