У меня проблема с моим списком Android. В моем списке используется настраиваемый элемент arrayadapter, который устанавливает onClickListener для изображения сообщения, а в списке есть onItemClickListener. Все работает отлично, но, как вы можете видеть на скриншоте ниже, изображение не заполняет его родительским. Поэтому, когда я нажимаю выше, снизу или справа от изображения, вызывается onItemClickListener.
Мое желание состоит в том, чтобы полностью разделить строку на две части. И я считаю, что решение этого кроется в row.xml или xml для ListView. Как я могу заполнить всю строку своим изображением?
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
android:id="@+id/android:list"
android:fastScrollEnabled="true"
android:listSelector="@drawable/listitem_background"
android:layout_height="wrap_content"
android:layout_width="fill_parent"></ListView>
Удалите прокомментированное свойство android:padding="6dip"
, поместите его в ImageView или в другое место, но не в родительский 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>
Какое изображение вы хотите заполнить всей строкой Первое изображение или последнее изображение?
Для обоих ImageViews вы продолжаете заполнение, то как они могут заполнить родительский?
Пожалуйста, проверьте код один раз, и ваш вопрос также не ясен.
Я видел, как вы скриншот, и я думал, что вы говорите о втором представлении изображения.
Если да, то удалите дополнение в ImageView.
Я думаю, это поможет вам.