1

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.

Community
  • 1
  • 1
  • That should not happen. Check to see if your list item background drawable has a padding or a margin. If that is not the case, it may help if I can view your drawable that you use. – achie Feb 29 '12 at 23:14
  • they are .png images - how would it be possible to put a background or padding on it? (sorry for the delayed response - I was expecting a notification) – Tevi Hirschhorn Mar 20 '12 at 16:44
  • They are just plain images. They can have a transparent background or padding since they are png. Just check it in an image viewer which displays the image with transparency also and you will see if they have anything of that kind. Or post the images and put the link here and people may try to reproduce the issue. And regarding notifications, you will get notifications on stackoverflow website. Just visit the site periodically after you ask the question. It will appear as a number in red circle on the left hand top of the tiny stackexchange link. – achie Mar 20 '12 at 18:36

0 Answers0