Android fail: ListView sets the split line color, androidlistview
Use the following code to set the separator line color. If it is invalid, the split line is invisible. Even if the split line width is set to 100, the split line cannot be seen. From the two lines of code, there should be no problem, it is also a common method.
listView.setDividerHeight(1); listView.setDivider(new ColorDrawable(Color.GRAY));
Why is it invalid? Let's look at the source code of setDivider.
public void setDivider(Drawable divider) { if (divider != null) { mDividerHeight = divider.getIntrinsicHeight(); } else { mDividerHeight = 0; } mDivider = divider; mDividerIsOpaque = divider == null || divider.getOpacity() == PixelFormat.OPAQUE; requestLayout(); invalidate(); }
Have you seen the following code?
if (divider != null) { mDividerHeight = divider.getIntrinsicHeight();
If the parameter is not blank, you need to obtain an internal default height. What is the height? refer to the following code:
public int getIntrinsicHeight() { return -1; }
The height returns-1. It's time to see the line!
From the source code, as long as the setDivider interface of ListView is called, mDividerHeight is set to 0 or-1, so you cannot see the line at all. If you want to see the line, you need to reverse the call order, as follows:
listView.setDivider(new ColorDrawable(Color.GRAY)); listView.setDividerHeight(1);
Here, I do not comment on the source code, but I personally think that this logic is really inappropriate. Setting the color should not change the basic parameters that have already been set.
Default delimiter color of android listview
Android: divider = ""
Set the split line style,
You can also set the height or something,
In the custom rounded corner ListView, how does one set the color of the split line ??
À setDivider (draw D) method to set the boundary resource. The parameter is null, which means that no boundary exists.