Transparent ListView in Android

Source: Internet
Author: User

When a list is rolled, the background of an item is transparent. After searching on the internet, I found that many people were asking questions about the black background of the list. The solutions provided during the communication were basically consistent.

First, the cause of the problem is that Android optimizes the display of the list scrolling, and uses the android: cacheColorHint color value in the layout file of the list to mix it with the item background, the default color value of the black topic is # FF191919, so the background is black.

The solution is to disable optimization. How can this problem be solved? You can set android: cacheColorHint to "@ android: color/transparent" or "@ android: color/transparent" to "#00000000 ".

In fact, this "off" is to set that color to transparent. Of course, you can set it to the same color as the background. Or set it to "@ null ". See this article: http://yuanzhifei89.iteye.com/blog/973724

Romain is a Google Android development engineer who is responsible for graphics and animation. It is said that ListView is his whole.

His blog is "Why is my list black? An Android optimization. What kind of optimization has been made, and how has this phenomenon been produced? The article makes it clearer. The solution is also provided at the end of this article, which is the most authoritative answer.

However, all the discussions I found are not the same as what I encountered.

It seems that the entire list background is black or transparent, or at least the background of all items except the selected items is black or transparent.

What I encountered was that the background of an item was transparent. Items with different output conditions are random.

In the layout file of listview, android: cacheColorHint has been set to "@ android: color/transparent", and changed to "#00000000.

When there is almost no way to implement it, I understood Romain's optimization ideas and tried to set android: cacheColorHint to the background color of listview.

However, the listview texture is used as the background, while android: cacheColorHint does not support resource setting.

Therefore, try to give it an opaque color value that is close to the color of the background color. Fortunately, this picture is not colorful. Although it is progressive, it is difficult to identify it at a glance.

Okay, it's a temporary solution.

This problem occurs only on Lenovo s890. Does anyone know why?

[Edit] A few days later, I saw this problem again. I found that for the background texture listview, The cacheColorHint color value cannot be set. I can use this method to disable the optimization.

android:scrollingCache="false"

The default value is "true". Enabling optimization can make render faster, but requires more memory. Test whether optimization is acceptable.

Related Article

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.