Style settings in android listview properties

Hello viewer, You can now have our Tutorial Lessons in your android mobile device and read it offline.
Download kotlin Programming APP on PlayStore
Download Website SEO Lessons APP on PlayStore

Style settings in android listview properties.

In Android, ListView and its properties (headerDividersEnabled, choiceMode, footerDividersEnabled, dividerHeight, divider, entries etc) is the most commonly used control, UI design done, many people want to be able to change its background, so that he can meet the overall UI design, change the background back is very simple just need to prepare a picture and then Once you do this, you’ll see that the background is changed. “Style settings in android listview properties.” But when you drag, or when you click on a list of empty positions, you see that the ListItem is turned into a listener. Black, and destroyed the overall effect.

Style settings in android listview properties - Style settings in android listview properties - Style settings in android listview properties - headerdividersenabled listview properties

This is why?

This Listview effect from the start, the default ListItem background is transparent, and ListView background is fixed, so scroll in the rolling process if the real time to go to the current display of each Item with the background Mixed operation, android system in order to optimize the use of this process, it uses a property called android: cacheColorHint in the black theme default color value is # 191919, so there just the picture, half of the black.

headerDividersEnabled

Then what should we do with listview?

If you just change the color of the background, you can directly specify the android: cacheColorHint you want the color, if you are using pictures to do the background, then it will be as long as the android: cacheColorHint designated as transparent (# 00000000) can, of course, Beautification is to sacrifice some efficiency. Finally, do not return to the above mentioned results you do not want to!

-Style settings in android listview properties.

Customize the split line between the ListView lines

In the Android platform, the system control provides a flexible customization options, all based on ListView or AbsListView implementation of the widget control can be set through the following method of dividing line spacing line, the dividing line can customize the color, or picture. In the ListView, we use the attribute android: divider = “# FF0000” to define the delimiter as red. Of course, the value here can point to a drawable picture object, if the use of the picture may be higher than the system default pixel, you can set the height of 6 pixels Android: dividerHeight = “6px”, of course, in the Java ListView also have related methods can be set.

headerDividersEnabled

-Style settings in android listview properties.

1) Click on Item without background color change

Add the following properties to the ListView control in the xml file:

Android: listSelector = “@ drawable / timer_list_selector”

Define the attribute value for timer_list_selector in the 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="<a href="http://my.oschina.net/asia" target="_blank">@android</a> :color/transparent" />
    </selector>

In the values ​​folder colors.xml defined transparent as follows:

<color name="transparent">#50000000</color>

2) There is no gap between items

In the xml file ListView control by adding the following attributes:

android:divider="#00000000"

Or in javaCode as follows:

ListView.setDividerHeight (0);

3) Calling the notifyDataSetChanged () method in a custom BaseAdapter will call the baseView’s getView () method again.

 

Android listview property nameAndroid listview properties description

Android: choiceMode

Specifies the selection mode used by this ListView. By default, list does not select a mode. The value of the property must be set to one of the following constants: none, a value of 0 for unselected mode, and singleChoice with a value of 1, indicating that at most one item is selected; multipleChoice with a value of 2 indicates that multiple items can be selected. See global attribute resource symbol choiceMode.

Android: divider

Specifies that the List items are separated by a graphic or color. You can also refer to an existing resource as “@ [+] [package:] type: name” or “? [Package:] [type:] name”; you can also use “#rgb” “#argb”, “# rrggbb” or “#aarrggbb” to represent a particular color. See the global property resource symbol divider.

Android: dividerHeight

The height of the separator. If no height is specified, the height inherent to this separator is used. Must be a floating-point number with a unit, such as “14.5sp”. The available units are px (pixel pixels), dp (density-independent pixels), sp (scaled pixels based on preferred font size), in (inches inches), mm (Millimeters mm). You can point to a resource that contains this type of value in the format “@ [package:] type: name” or “? [Package:] [type:] name” (subject property). See the global attribute resource symbol dividerHeight.

Android: entries

Reference an array to be used in this ListView. If the array is fixed, the use of this attribute will be easier than in the process of writing. You must point to a resource in the form of “@ [+] [package:] type: name” or “? [Package:] [type:] name”. 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. This property defaults to true. The attribute value must be set to true or false. You can point to a resource that contains this type of value in the format “@ [package:] type: name” or “? [Package:] [type:] name” (subject property). See global attribute resource symbol footerDividersEnabled.

Android: headerDividersEnabled

When set to flase, this ListView will not draw delimiters after the header view. This property defaults to true. The attribute value must be set to true or false. You can point to a resource that contains this type of value in the format “@ [package:] type: name” or “? [Package:] [type:] name” (subject property). See the global attribute resource symbol headerDividersEnabled.

Intentions of friends should be able to find, set the background in the listview after. There will be some problems.

-Style settings in android listview properties.

1., listview in the drag when the background image disappears into a black background. Wait until the drag to complete our own background picture is displayed.

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

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

For the above problem in the listview of the xml file to set the following statement.

Problem 1 has the following code knot solved android: scrollingCache = “false”

Problem 2 is solved with the following code: android: fadingEdge = “none”

Problem 3 is solved with the following code: android: divider = “@ drawable / list_driver” where @ drawable / list_driver is an image 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>

-Style settings in android listview properties

About The Author

Related posts

Leave a Reply