Android custom Listview split line

Source: Internet
Author: User

Android custom Listview split line

Each Item in ListView has a split line. Setting android: footerDividersEnabled indicates whether to display the split line. The default value is true.

1. If the split line is not displayed, add android: footerDividersEnabled = false to the ListView control.

 

[Html]
  1. Android: id = @ + id/local_groups_list
  2. Android: layout_width = match_parent
  3. Android: layout_height = wrap_content
  4. Android: footerDividersEnabled = false/>

     

    2. To change the color and width of the split line of ListView, you must define the android: divider and android: dividerHeight attributes in the layout.

     

    [Html]
    1. Android: id = @ + id/local_groups_list
    2. Android: layout_width = match_parent
    3. Android: layout_height = wrap_content
    4. Android: divider = @ color/divider_color
    5. Android: dividerHeight = 1px/>


       

      Attribute name

      Description

      Android: choiceMode

      Specifies the selection mode used by the ListView. The list mode is not selected by default.

      The attribute value must be set to one of the following constants: none; the value is 0, indicating no selection mode;

      SingleChoice, with a value of 1, indicates that up to one item can be selected;

      MultipleChoice. The value is 2, indicating that multiple items can be selected.

      See the global attribute resource symbol choiceMode.

      Android: divider

      Specifies that List items are separated by a certain image or color. You can use @ [+] [package:] type: name or? [Package:] [type:] name (topic attribute) to point to an existing resource. You can also use # rgb, # argb, # rrggbb or # aarrggbb format to indicate a color.

      See the global attribute resource symbol divider.

      Android: dividerHeight

      The height of the separator. If the height is not specified, the inherent height of this separator is used. It must be a floating point in units, such as 14.5sp. Available units such as px (pixel), dp (density-independent pixels irrelevant to the density ), sp (scaled pixels based on preferred font size is a fixed proportion of pixels based on the font size), in (inches), mm (millimeters ).

      You can use @ [package:] type: name

      Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

      See the global attribute resource symbol dividerHeight.

      Android: entries

      Reference an array that will be used in this ListView. If the array is fixed, using this attribute is easier than writing in a program.

      It must start with @ [+] [package:] type: name or? [Package:] [type:] name to point to a resource.

      See the global attribute resource symbol entries.

      Android: footerDividersEnabled

      When set to flase, this ListView will not draw a separator before the footer view. The default value of this attribute is true.

      The property value must be set to true or false.

      You can use @ [package:] type: name

      Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

      See the global attribute resource symbol footerDividersEnabled.

      Android: headerDividersEnabled

      When set to flase, this ListView will not draw a separator behind the header view. The default value of this attribute is true.

      The property value must be set to true or false.

      You can use @ [package:] type: name

      Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

      See the global attribute resource symbol headerDividersEnabled.

       

      Conflict:

      1. When the listview is dragged, the background image disappears into a black background. After the drag is completed, our own background image will be displayed.

      2. There is a black shadow on the top and bottom of the listview.

      3. Set an image as the interval between each item in lsitview.

      Set the statement in the xml file of listview to solve the above problem.

      Problem 1: Solve android with the following code: scrollingCache = false

      Problem 2: Use the following code to solve the problem: android: fadingEdge = none
      Problem 3: Use the following code to solve the problem: android: divider = @ drawable/list_driver where @ drawable/list_driver is an image resource.

       

      Overall:

      Android: id = @ + id/myListView01
      Android: layout_width = fill_parent
      Android: layout_height = 300dip
      Android: fadingEdge = none
      Android: divider = @ drawable/list_line
      Android: scrollingCache = false
      Android: background = @ drawable/list_background>

      Attribute name

      Description

      Android: choiceMode

      Specifies the selection mode used by the ListView. The list mode is not selected by default.

      The attribute value must be set to one of the following constants: none; the value is 0, indicating no selection mode;

      SingleChoice, with a value of 1, indicates that up to one item can be selected;

      MultipleChoice. The value is 2, indicating that multiple items can be selected.

      See the global attribute resource symbol choiceMode.

      Android: divider

      Specifies that List items are separated by a certain image or color. You can use @ [+] [package:] type: name or? [Package:] [type:] name (topic attribute) to point to an existing resource. You can also use # rgb, # argb, # rrggbb or # aarrggbb format to indicate a color.

      See the global attribute resource symbol divider.

      Android: dividerHeight

      The height of the separator. If the height is not specified, the inherent height of this separator is used. It must be a floating point in units, such as 14.5sp. Available units such as px (pixel), dp (density-independent pixels irrelevant to the density ), sp (scaled pixels based on preferred font size is a fixed proportion of pixels based on the font size), in (inches), mm (millimeters ).

      You can use @ [package:] type: name

      Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

      See the global attribute resource symbol dividerHeight.

      Android: entries

      Reference an array that will be used in this ListView. If the array is fixed, using this attribute is easier than writing in a program.

      It must start with @ [+] [package:] type: name or? [Package:] [type:] name to point to a resource.

      See the global attribute resource symbol entries.

      Android: footerDividersEnabled

      When set to flase, this ListView will not draw a separator before the footer view. The default value of this attribute is true.

      The property value must be set to true or false.

      You can use @ [package:] type: name

      Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

      See the global attribute resource symbol footerDividersEnabled.

      Android: headerDividersEnabled

      When set to flase, this ListView will not draw a separator behind the header view. The default value of this attribute is true.

      The property value must be set to true or false.

      You can use @ [package:] type: name

      Or? The format of [package:] [type:] name (topic attribute) directs to a resource that contains this type of value.

      See the global attribute resource symbol headerDividersEnabled.

      Attentive friends should find that after the background is set in listview. There will be some problems.

      1. When the listview is dragged, the background image disappears into a black background. After the drag is completed, our own background image will be displayed.

      2. There is a black shadow on the top and bottom of the listview.

      3. Set an image as the interval between each item in lsitview.

      Set the statement in the xml file of listview to solve the above problem.

      Problem 1: Solve android with the following code: scrollingCache = false

      Problem 2: Use the following code to solve the problem: android: fadingEdge = none
      Problem 3: Use the following code to solve the problem: android: divider = @ drawable/list_driver where @ drawable/list_driver is an image resource.

       

      Overall:

      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>

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.