In Android, the ListView is the most commonly used control, when doing UI design, many people want to be able to change its background, so that he can conform to the overall UI design, change the background is very simple only need to prepare a picture and then specify the properties android:background= "@drawable/bg", but do not be happy too early, when you do this, you find that the background is changed, but when you drag, or click on the list blank position to find that ListItem have become black, destroying the overall effect
What is this for?
This to start with the ListView effect, the default ListItem background is transparent, and the ListView background is fixed, so in the process of scrolling through the scroll bar if the current display of each item is mixed with the background, So the Android system in order to optimize the process, using a property called Android:cachecolorhint, under the black theme of the default color value is #191919, so there is just the picture, half is black.
What about that?
If you just change the color of the background, you can directly specify Android:cachecolorhint as the color you want, if you are using a picture to do the background, it will be as long as the android:cachecolorhint is specified as transparent (#00000000) can be , of course, in order to beautify is to sacrifice some efficiency. In the end, it doesn't come back to the results you don't want!
Customizing split lines between rows in a ListView
System controls in the Android platform provide flexible customization options, and all widget controls that are based on the ListView or Abslistview implementation can set line spacing split lines by using the following method, which allows you to customize the color, or picture. In the listview we use the attribute android:divider= "#FF0000" to define the delimiter to be red, of course, here the value can point to a drawable picture object, if the use of the picture may be higher than the system default pixels, you can set the height such as 6 pixels Android:dividerheight= "6px", the Android Development network hint of course in Java in the ListView also has related methods can be set. |
1) No background color changes when clicking on item
Add the following attribute to the ListView control in the XML file:
Android:listselector= "@drawable/timer_list_selector"
Defining Timer_list_selector property values in drawable
The timer_list_selector.xml is defined as follows:
<?xml version= "1.0" encoding= "Utf-8"?>
<selector xmlns:android= "Http://schemas.android.com/apk/res/android" >
<item android:state_selected= "true" android:drawable= "@android: Color/transparent"/>
</selector>
The transparent is defined in Colors.xml under the Values folder as follows:
<color name= "Transparent" > #50000000 </color>
2) Set no gap between item
Add the following attribute to the ListView control in the XML file:
Android:divider= "#00000000"
Or, as defined in Javacode:
Listview.setdividerheight (0);
3) calling the Notifydatasetchanged () method in a custom baseadapter will recall the Baseadapter GetView () method.
Property name |
Describe |
Android:choicemode |
Specifies the selection mode used by this ListView. By default, the list has no selection mode. The property value must be set to one of the following constants: None, with a value of 0, indicating no selection mode; Singlechoice, a value of 1, indicates that a maximum of one item can be selected; Multiplechoice, a value of 2, indicates that multiple items can be selected. You can see the global attribute resource symbol Choicemode. |
Android:divider |
Specifies that a graphic or color is used to separate the list items. Can you use "@[+" [Package:]type:name] or "? [Package:] [Type:]name] to point to an existing resource, or to represent a color using the format "#rgb", "#argb", "#rrggbb", or "#aarrggbb". You can see the global attribute resource symbol divider. |
Android:dividerheight |
The height of the delimiter. If no height is specified, the height that is intrinsic to this delimiter is used. Must be a floating-point number with units, such as "14.5SP". Available units such as px (pixel pixels), DP (density-independent pixels with density independent pixels), SP (scaled pixels based on preferred font size A fixed percentage of pixels based on the font size), in (inches inch), mm (millimeters mm). You can use the @[package:]type:name "or"? [Package:] The format of [Type:]name] (theme property) to point to a resource that contains this type of value. You can see the global attribute resource symbol Dividerheight. |
Android:entries |
A reference to an array that will be used in this ListView. If the array is fixed, using this property will be simpler than writing in the program. Must be "@[+][package:]type:name" or "? [Package:] The [Type:]name] form to point to a resource. You can see the global attribute resource symbol entries. |
Android:footerdividersenabled |
When set to Flase, this ListView will not draw a delimiter in front of the footer view. The default value for this property is true. The property value must be set to TRUE or false. You can use the @[package:]type:name "or"? [Package:] The format of [Type:]name] (theme property) to point to a resource that contains this type of value. You can see the global attribute resource symbol footerdividersenabled. |
Android:headerdividersenabled |
When set to Flase, this ListView will not draw a delimiter after the header view. The default value for this property is true. The property value must be set to TRUE or false. You can use the @[package:]type:name "or"? [Package:] The format of [Type:]name] (theme property) to point to a resource that contains this type of value. You can see the global attribute resource symbol headerdividersenabled. |
A friend of intentions should find out that the ListView is after setting the background. There will be some problems.
1. When the ListView is dragged, the background picture disappears into a black background. Wait until we have finished dragging our own background image to show it.
2, the top and bottom of the ListView has a black shadow.
3, Lsitview between each item need to set a picture to do as the interval.
Set the statement in the ListView XML file for the above issues.
Issue 1 has the following code knot to resolve Android:scrollingcache= "false"
Problem 2 is resolved with the following code: android:fadingedge= "None"
Problem 3 is resolved with the following code: android:divider= "@drawable/list_driver" where @drawable/list_driver is a picture resource
Overall as follows
<listview
Android:id= "@+id/mylistview01"
Android:layout_width= "Fill_parent"
android:layout_height= "287dip"
Android:fadingedge= "None"
android:divider= "@drawable/list_driver"
Android:scrollingcache= "false"
android:background= "@drawable/list" >
</ListView>
Some styling settings for the ListView in Android