In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about the small knowledge of ListView, which may not be understood by many people. In order to let you know more, Xiaobian summarized the following contents for you. I hope you can gain something according to this article.
In Android, ListView is one of the most commonly used controls. When doing UI design, many people want to be able to change its background so that it can conform to the overall UI design. Changing the background is very simple. You only need to prepare a picture, and then specify the attribute android:background="@drawable/bg". However, don't be too happy. When you do this, you will find that the background has changed, but when you drag or click the blank position of the list, you will find that ListItems have turned black, destroying the overall effect, as shown below:
Why is that?
This starts with the effect of Listview. The default ListItem background is transparent, while the ListView background is fixed. Therefore, if the display content of each Item is mixed with the background in real time during the scrolling process of the scroll bar, the android system uses an attribute called android:cacheColorHint in order to optimize this process. The default color value under the black theme is #191919, so the picture just appeared. Half of it is black.
What should we do?
If you just change the background color, you can directly specify android:cacheColorHint as the color you want. If you use an image as the background, then you only need to specify android:cacheColorHint as transparent (#000000). Of course, in order to beautify it, you have to sacrifice some efficiency. *** Do not return to appear above said you do not want the result!
Custom ListView line dividers
In Android platform, the system controls provide flexible customization options. All widget controls based on ListView or AbsListView can set the line spacing by the following method. The line can customize color, or image.
In ListView we use the attribute android:divider="#FF0000" to define the separator as red, of course, the value here can point to a drawable image object, if the image may be higher than the system default pixels, you can set the height yourself such as 6 pixels android:dividerHeight="6px", of course, ListView in Java also has related methods can be set.
No background color change when clicking Item
Add the following attributes to the ListView control in the xml file:
android:listSelector="@drawable/timer_list_selector"
Define the attribute value of timer_list_selector in drawable
timer_list_selector.xml is defined as follows:
Define transparent in colors.xml under the values folder as follows:
#50000000
Set No Gap Between Items
Add the following attributes to the ListView control in the xml file:
android:divider="#00000000"
Or, in javaCode, define:
listView.setDividerHeight(0);
Calling the notifyDataSetChanged() method in a custom BaseAdapter re-invokes the BaseAdapter's getView() method.
After setting the background in listview, there are some problems:
1.、listview background image disappears into black background when dragging. We wait until we finish dragging before our own background image appears.
There are black shadows above and below listview.
3. A picture needs to be set as an interval between each item of lsitview.
For the above problem, set the following statement in the xml file of listview.
Problem 1 is solved by android:scrollingCache="false"
Problem 2 is solved with android:fadingEdge="none"
Problem 3 is solved as follows: android:divider="@drawable/list_driver" where @drawable/list_driver is an image resource
The overall picture is as follows:
After reading the above, what do you know about ListView? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.