How Do I Avoid Double Borders Between Lists?
Solution 1:
In order to not have double selectors(and in proper positions like also at the top, at the bottom) you have two cases that you need to tackle, the top element(which needs the selector at the top and bottom) plus every other row which needs the selector only at the bottom(the top will be covered by the selector of the previous element). This has to be done in code, in your adapter(if you were using a simple table you could have just made one drawable for the top element and one for the other elements):
- remove the properties like
android:top
,android:bottom
etc from thelayer-list
(as you'll be setting those in code) - in the
getView()
method of the adapter retrieve the background of the row view(which will be aLayerDrawable
) - based on the position you have(mainly 0 vs any oher position) use the
LayerDrawable.setLayerInset()
method and set the inset for the layer with index 1(if that is your complete drawable): top and bottom for the first element, top(with a value of 0) and bottom for every other position
Solution 2:
You could play with ListView
params android:divider
and android:dividerHeight
, to set a line separator of the color and height you want.
Solution 3:
The reason for having two lines is, that the background (second layer) lets shine thru the white part on both ends, at the bottom and the top. Therefore every list entry gets a white line on top and on bottom. As list items have a small distance between each other you see two lines.
Two things you need to do
For each item, let only one (top or bottom) shine thru. Therefore you get only one line per item. The drawable XML for an item:
<layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapeandroid:shape="rectangle"><solidandroid:color="@color/white" /><cornersandroid:radius="0dp" /></shape></item><itemandroid:top="1dp"android:left="0dp"android:right="0dp"android:bottom="0dp"><shapeandroid:shape="rectangle"><solidandroid:color="#262626" /><cornersandroid:radius="0dp" /></shape></item></layer-list>
For the whole list, you need the drawable that shows the one missing line. The drawable XML for this looks nearly the same. Just bottom and top is exchanged:
<layer-listxmlns:android="http://schemas.android.com/apk/res/android" ><item><shapeandroid:shape="rectangle"><solidandroid:color="@color/white" /><cornersandroid:radius="0dp" /></shape></item><itemandroid:top="0dp"android:left="0dp"android:right="0dp"android:bottom="1dp"><shapeandroid:shape="rectangle"><solidandroid:color="#262626" /><cornersandroid:radius="0dp" /></shape></item></layer-list>
Post a Comment for "How Do I Avoid Double Borders Between Lists?"