So, I have a layout (as a row in a ListView) and I have listSelector. This listSelector works fine until I add a background to the layout. I want this background there as the starting background (and will change with listSelector). But once I add a background, the listSelector no longer works and my layout doesn't change colors when I press it (like expected). Why is this? Thanks.
The Layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/listview_background"
android:listSelector="@drawable/listview_selector"
android:minHeight="140dip"
android:paddingLeft="5dp"
android:paddingRight="5dp" >
<ImageView
android:id="@+id/imgIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="2dip"
android:layout_toRightOf="@id/tvTime"
android:adjustViewBounds="true"
android:maxWidth="100dip"
android:padding="4dip"
android:scaleType="centerInside"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
The background:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<!-- The border color -->
<solid android:color="#CCCCCC" />
</shape>
</item>
<item android:left="5dp" android:right="5dp" >
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<!-- The fill color-->
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
And the List Selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/listview_bg_hover" android:state_pressed="true"/>
<item android:drawable="@drawable/listview_background" android:state_focused="true"/>
<item android:drawable="@drawable/listview_background"/>
</selector>
No comments:
Post a Comment