Resolves an issue where the ListView property divider setting is invalid

Source: Internet
Author: User

Use the following code to set the separation line color, invalid, unexpectedly can not see the split line, even if the width of the split line is 100, can not see, from the two lines of code to see, there should be no problem, it is also a very conventional wording.

[Java] view plain copy listview.setdividerheight (1); Listview.setdivider (New colordrawable (Color.gray));
Why not? Look at the source of Setdivider.

[Java] view plain copy public void Setdivider (drawable divider) {if (divider! = null) {Mdivid       Erheight = Divider.getintrinsicheight ();       } else {mdividerheight = 0;       } Mdivider = divider; Mdividerisopaque = Divider = = NULL | |       Divider.getopacity () = = Pixelformat.opaque;       Requestlayout ();   Invalidate (); }
See the code below?

[Java] view plain copy if (divider! = null) {mdividerheight = Divider.getintrinsicheight ();
If the parameter is not empty, to get an internal default height, what is this height, see the code below

[Java] view plain copy public int getintrinsicheight () {return-1; }
Height return-1, you can see the line before the ghost.

From the source code, as long as the ListView Setdivider interface is called, the Mdividerheight will be set to 0 or-1, so you can not see the line, if you want to see the line, it is necessary to call the order in turn, as follows

[Java] view plain copy listview.setdivider (new Colordrawable (Color.gray)); Listview.setdividerheight (1);
Here, do not comment on its source code, but personally think such logic is really inappropriate, set the color should not be set up the basic parameters have been modified.

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.