ListView Common Properties (2012-01-12 17:20:27)

Source: Internet
Author: User

Compare special properties to make a more aesthetically pleasing list by setting such properties

stackfrombottom--
after setting this property, your latest entry will show you the bottom of your list,
The value is true and false, such as
android:stackfrombottom= "true"

The Transciptmode property--listview automatically slides to the bottom to display the most recent entry. Used in a ListView or other control that displays a large number of items to track or view information in real time, and you want the latest entries to automatically scroll to the viewable range. such as:
android:transcriptmode= "Alwaysscroll"

Cachecolorhint Properties--Settingsthe cached color when redrawing. Usually when you passspecifies that the property android:background= "@drawable/bg" to change the listview background, although the background has changed,But when you drag, or click on the list blank position, it turns out the ListItem is black.
Why is it?
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.
to avoid this situation, you need to set this property:the android:cachecolorhint is specified as transparent (#00000000).
If you just change the color of the background, you can specify Android:cachecolorhint as the color you want.

Fadingedge Property--black shadow on top and bottom, no shadow after android:fadingedge= "None" ~

ScrollBars Property--hides the scroll bar of the ListView, android:scrollbars= "None" with setverticalscrollbarenabled (true); the effect is the same, hidden when inactive, The time of the event is also hidden.

Fadescrollbars Property--android:fadescrollbars= "True" when configuring the ListView layout, setting this property to True enables the auto-hide and display of scroll bars.

Divider Properties--Sets the line spacing split line, the split line can 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.

Note: If the style does not work after you set the android:divider= "#0000" property, you can set android:dividerheight= "not 0 value".

When using XML, you can use the Android:divider property to set the style (color or resource file) of the split line for the ListView, and the method provided by default in Java code, Listview.setdivider ()
But only support drawable resource files, for this cost a little time to solve the method, later found that it is very simple, Android provides a way to create a color resource file, so only need to use
Listview.setdivider (new colordrawable (color))
can solve the problem.
If divider is set to no effect, set dividerheight to nonzero.

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);


Listselector Properties--Sets the color after the list item is selected or clicked, you can set the android:listselector= "@null", and no background color changes when the list item is selected or clicked.


Other properties:

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.

Issue 1 has the following code knot to resolve Android:scrollingcache= "false"

2, the top and bottom of the ListView has a black shadow.

Problem 2 is resolved with the following code: android:fadingedge= "None"

3, Lsitview between each item need to set a picture to do as the interval.

Problem 3 is resolved with the following code: android:divider= "@drawable/list_driver" where @drawable/list_driver is a picture resource

ListView Common Properties (2012-01-12 17:20:27)

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.