Reputation: 3192
I have listview, which uses MergeAdapter (it can combine different adapters in itself and act as compound adapter). My problem: it has transparent space between 1st and 2nd items (that is 100% not a divider, I have different divider). By the way, there is no divider between 1st and 2nd items. I loaded my listview's view hierarchy in hierarchyviewer (it consisted of 3 items, only 3 for testing purposes) and this is what I discovered:
1st item was placed in 0-36px on vertical axis (36px height, 0px - top)
2nd item was placed in 41-191px (150px height, 41px - top)
3rd item was placed in 196-346px (150px height, 196px - top)
All items' width is match_parent.
I see transparent space between 1st and 2nd items (I cant measure it, but it is about 5px, just like difference between end of 1st item and beginning of the second one). However, I see no transparent space between 2nd and 3rd items despite the fact the 2nd one ends in 191px and the 3rd one begins in 196px. It seems, android automatically fills this 5-pixel-area using background color in case of 2nd-3rd items, but doesn't do it in the case of 1st-2nd items.
Can anyone explain me how it all works? I can misunderstand something. I'm not sure my assumptions are right.
Besides, my objective is to get rid of space between 1st and second item.
P.S. For those who have ever worked with MergeAdapter, I have some observations specific to this adapter, when I use:
adapter.addView(myView, false);
it displays views with transparent area mentioned above (with no divider between myView and next ListView item). And when I use:
adapter.addView(myView, true);
I see no transparent area, but divider. In fact, I need neither divider nor transparent area. How to archieve this?
P.P.S. I cannot place myView above ListView itself despite the fact myView is the 1st element in ListView, because sometimes it is added somewhere in the middle of ListView.
Upvotes: 1
Views: 2029
Reputation: 34765
ListView has two method use it and try ....
listView.setDivider(Drawable divider);//listView.setDivider(R.drawable.divider);
listView.setDividerHeight(int height);//listView.setDividerHeight(0);
will solve your issue
Upvotes: 4