[Android Pro] Android control the top or bottom of the ListView also shows the split line

Source: Internet
Author: User

Reference to:http://blog.csdn.net/lovexieyuan520/article/details/50846569

The default Android control in the ListView is not displayed on the top of the splitter line, but we can use some tricks to display it. Let's look at the effect of the ListView display by default:

Can see the top is no split line, but sometimes our art is simply drawn on the above a split line, no way, we have to add, we add a header on the top of the ListView can be implemented, the code is as follows

Listview.addheaderview (new viewstub (this));

With this code, you'll see a split line at the top.

See, we've added a split line to the top of the ListView, but notice that the ListView has a property whose android:headerDividersEnabled default value is true, which means that the default is to display the splitter line of the header, and if we set it to false it won't show the split line.
We set up the split line at the top, and below we set the split line at the bottom, which is a bit trickier than setting the top divider. If we set the ListView's Android:layout_height to Wrap_content, the situation is the same as the top plus split line:

Listview.addfooterview (new viewstub (this));


We see the bottom split line has been added, but pay attention to the Android:footerdividersenabled property, and Android:headerdividersenabled is the same, no longer repeat.
If we set the Android:layout_height of the ListView to Match_parent or a specific value, the effect is as follows


The split line at the bottom is actually half as thick. When the height of the ListView content is less than the height of the ListView, then the ListView will add a split line to the last item, this time the two split lines are superimposed, so the bottom of the split line becomes wider.
In general, when we use the ListView, we set the android:layout_height to wrap_content so that there is no problem, but sometimes we need to fix the ListView at a certain height, and then scroll beyond that height. , we can set a container on the outside of the ListView, such as Framelayout,listview's Android:layout_height or wrap_content, When the content of the ListView exceeds the height of the framelayout, the scroll bar is displayed, and the split line is not displayed under the last item.
Finished, hope to benefit everyone!!!

[Android Pro] Android control the top or bottom of the ListView also shows the split line

Related Article

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.