0

I'm trying to create list item with blue overlay on top of the item. The blue overlay only appear when user touch on the item. So I'm placing view with background drawable to cover the whole item.

The problem now is that this View never get drawn at all. I could switch the background to simple color and it would not appear. If I change it to TextView instead, the text will be shown but not covered the whole item. What am I doing wrong?

The layout get updated for sure, if I change color of any TextView it would apply that change accordingly.

Here's a layout for the list item.

<?xml version="1.0" encoding="utf-8"?>

..<!-- other stuff -->..

<View
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/item_overlay"
        android:duplicateParentState="true"
        android:visibility="visible"
        />

RobGThai
  • 5,937
  • 8
  • 41
  • 59
  • You mean when list item is pressed you want its color to be changed,it is so ? – kaushal trivedi Jul 09 '13 at 11:12
  • Yes, but let me be specific. I know how to make background selector drawable to change background color. But I want an overlay color that lays on top of ImageViews and TextViews that I have in the list item layout. – RobGThai Jul 09 '13 at 11:55

1 Answers1

2

1) You can list selector, along with option drawSelectoronTop

 <ListView android:listSelector="@drawable/list_selector" 
   android:drawSelectorOnTop="true">
</ListView>

setting drawSelectoronTop true will cause the drawable to draw over the list item(ForeGround)

2) If list selector can't be applied to your particular design, you can use FrameLayout as the list item's parentView, with foreground property

android:foreground="@drawable/list_selector"

for more about this you can refer the post Draw selector on top - for a basic linear layout?

Community
  • 1
  • 1
Sreejith B Naick
  • 1,203
  • 7
  • 13
  • This isn't exactly what I asked for but this is better answer for what I wanted to do :D. Many thanks. – RobGThai Jul 10 '13 at 08:23