I created a custom layout (using LayoutInflator) for list items. Here are the relevant files:
my_list.xml - the main activity which has the ListView
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <ListView android:id="@android:id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:listSelector="@drawable/listitem_selector" > </ListView>
list_item.xml - references drawable .png for background
android:background="@drawable/list_item_bg"
listitem_selector.xml
<selector> <item android:state_focused="false" android:drawable="@drawable/list_item_bg" /> <item android:state_pressed="true" android:drawable="@drawable/list_item_pressed_bg" /> <item android:state_focused="true" android:drawable="@drawable/list_item_pressed_bg" /> </selector>
If I don't use the listitem_selector.xml to override the default state styles, I get the ugly default Android green/orange colors, but otherwise the layout looks fine. When I use the listitem_selector.xml, it adds extra space at the top of each list item. (if I use smaller images, it still adds space)
here's a screenshot: [edit - not screenshots allowed.]
How can I override the default list item state styling without adding the weird space?
p.s. - I referenced this very helpful post to get where I got.