Setting space between different items of a listView
I'm having the following problem: I have a ListView and I get the layout for its items from an xml file. The thing is, though, that there should be some space between sequential items which I accomplish by nesting my layout into a dummy RelativeLayout just so that I can set marginTop =" " to the layout containing the item. The problem is that when the user clicks an item of the ListView the whole area (including the gap between sequential items) becomes selected开发者_开发知识库. How do I deal with this? Thanks!
Instead of nesting items in a RelativeLayout, why not try using the listview's own "divider" to separate items?
In your ListView xml, add:
android:dividerHeight="15 dip"
(or some other value)
try this:
ListView android:id="@+id/MyListView"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:divider="@android:color/transparent"
android:dividerHeight="10.0sp"
Create your own List View by extending BaseAdapter class in a separate class. you can refer to this
精彩评论