Android Development (33) Customizing the split Line of the ListView (draw multiple lines with XML drawable)

Source: Internet
Author: User

I encountered a scenario where I needed to customize the splitter line of the ListView, which was made up of two lines, and it was difficult to use XML drawable.

Note: Draw two lines is to achieve the effect of the sunken, in the drawing of a dark line followed by a clearly will give a person visually obvious "ditch" feeling.

Because my background is transparent (background gradient), directly with the picture to achieve the effect is not good.

Look at the effect:

Use Layer-list to implement.

Layer-list can contain multiple item, each item is stacked together.

The layer-list item can be spaced and implemented using properties such as Android:bottom.

Specific practices:

1. Draw the first line first.

2. The second line sets the spacing, 1px from the head, so it does not overlap completely

3. Two lines stacked together

The specific code is as follows.

<?xml version= "1.0" encoding= "Utf-8"? ><layer-list xmlns:android= "http://schemas.android.com/apk/res/ Android "> <Item Android:bottom= "0px"Android:left= "0px"Android:right= "0px"Android:top= "0px" > <shape android:shape= "Rectangle" > <size Android:height= "1px"Android:width= "1px"/> <solid android:color= "#A18249"/> </shape> </item> <Item Android:bottom= "0px"Android:left= "0px"Android:right= "0px"Android:top= "3px" > <shape android:shape= "Rectangle" > <size Android:height= "2px"Android:width= "2px"/> <solid android:color= "@android: Color/white"/> </shape> </item></la Yer-list>

Reference: Http://stackoverflow.com/questions/14436641/understanding-androids-layer-list

Android Development (33) Customizing the split Line of the ListView (draw multiple lines with XML drawable)

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.