I have a problem with my Android listview. My list uses a custom arrayadapter, that sets an onClickListener for the message image and the list has an onItemClickListener. It all works fine, but as you can see in the screenshot below, the image doesn't fill it's parent. So when I click above, below or to the right of the image the onItemClickListener is called.
My wish is to completely divide the row in two sections. And I believe the solution to this lies in the row.xml or the xml for the ListView. How can i fill the entire row with my image?
row.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip"
android:background="@drawable/listitem_background"
android:id="@+id/row2">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/logominimini" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:textColor="@color/darkgreen"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="@color/black"
/>
</LinearLayout>
<TextView
android:id="@+id/divider"
android:layout_width="3dp"
android:layout_height="fill_parent"
android:background="@drawable/divider_background"
android:visibility="gone"/>
<ImageView
android:id="@+id/selectmessage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:visibility="visible"
android:paddingRight="20dp"
android:paddingLeft="40dp"
android:background="@drawable/listitem_background"
android:layout_marginLeft="0dip"
android:layout_marginRight="0dip"
android:layout_gravity="center_vertical"
android:src="@drawable/messageunselected" />
</LinearLayout>
Listview:
<ListView
android:id="@+id/android:list"
android:fastScrollEnabled="true"
android:listSelector="@drawable/listitem_background"
android:layout_height="wrap_content"
android:layout_width="fill_parent"></ListView>
Remove the commented property android:padding="6dip"
, put it in ImageView or elsewhere but not in parent LinearLayout
:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
<!-- remove this: android:padding="6dip" -->
android:background="@drawable/listitem_background"
android:id="@+id/row2">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_marginRight="6dip"
android:src="@drawable/logominimini" />
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:singleLine="true"
android:textColor="@color/darkgreen"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
android:textColor="@color/black"
/>
</LinearLayout>
<TextView
android:id="@+id/divider"
android:layout_width="3dp"
android:layout_height="fill_parent"
android:background="@drawable/divider_background"
android:visibility="gone"/>
<ImageView
android:id="@+id/selectmessage"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_centerVertical="true"
android:visibility="visible"
android:paddingRight="20dp"
android:paddingLeft="40dp"
android:background="@drawable/listitem_background"
android:layout_marginLeft="0dip"
android:layout_marginRight="0dip"
android:layout_gravity="center_vertical"
android:src="@drawable/messageunselected" />
</LinearLayout>