我有一个Android ListView,其中包含各有不同背景的行。我想在选择一行时设置一个半透明的背景,但是我找不到解决方法。我见过的所有答案都使用android:choiceMode和android:listSelector(要求在行视图上没有背景)或使用状态列表drawable(要求背景使用静态图像,而不是动态图像)根据我的情况得出的数据。)
<ListView
android:id="@+id/properties_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:choiceMode="singleChoice"
android:listSelector="@android:color/darker_gray"
android:divider="@color/white"
android:dividerHeight="0dp" />
有什么想法可以做到吗?
根据要求,这是属性行的布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:rpr="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="@dimen/search_list_item_height">
<RelativeLayout
android:id="@+id/property_row_details_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/property_row_border"
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="@color/white"
android:layout_alignParentTop="true"
android:visibility="gone" />
<RPR.Mobile.Droid.Widget.CachedImageView
android:id="@+id/property_row_photo"
android:layout_below="@+id/property_row_border"
android:layout_width="match_parent"
android:layout_height="@dimen/search_list_item_height"
android:scaleType="centerCrop" />
<RelativeLayout
android:id="@+id/property_row_highlight"
android:layout_below="@+id/property_row_border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#99FEF0CC"
android:visibility="gone" />
<RPR.Mobile.Droid.Widget.CachedImageView
android:id="@+id/property_row_gradient"
android:layout_width="match_parent"
android:layout_height="@dimen/search_list_item_gradient_height"
android:src="@drawable/property_row_gradient"
android:layout_alignParentBottom="true" />
<RPR.Mobile.Droid.Widget.ScaleImageView
android:id="@+id/property_row_status"
android:layout_below="@+id/property_row_border"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true" />
<RelativeLayout
android:id="@+id/property_row_status_and_type_container"
android:layout_toRightOf="@+id/property_row_status"
android:layout_width="@dimen/search_list_item_status_and_type_width"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/property_row_status"
android:layout_alignBottom="@+id/property_row_status"
android:gravity="center_vertical"
android:background="#80000000"
android:paddingLeft="@dimen/padding_half">
<TextView
android:id="@+id/property_row_status_and_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_small"
android:textColor="@color/white"
android:singleLine="true"
android:ellipsize="end" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/property_row_open_house_container"
android:layout_toRightOf="@+id/property_row_status_and_type_container"
android:layout_toLeftOf="@+id/property_row_photo_count_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/property_row_status"
android:layout_alignBottom="@+id/property_row_status"
android:gravity="center_vertical"
android:background="#CC000000"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding"
android:visibility="gone">
<TextView
android:id="@+id/property_row_open_house"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_small"
android:textColor="@color/yellow_gold"
android:singleLine="true"
android:ellipsize="end" />
</RelativeLayout>
<LinearLayout
android:id="@+id/property_row_photo_count_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/property_row_status"
android:layout_alignBottom="@+id/property_row_status"
android_orientation="horizontal"
android:gravity="center_vertical"
android:background="#80000000"
android:layout_alignParentRight="true"
android:paddingLeft="@dimen/padding"
android:paddingRight="@dimen/padding">
<TextView
android:id="@+id/property_row_photo_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_small"
android:textColor="@color/white"
android:singleLine="true"
android:ellipsize="end" />
<RPR.Mobile.Droid.Widget.CachedImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/property_row_photo_count"
android:layout_marginLeft="@dimen/padding_half" />
</LinearLayout>
<LinearLayout
android:layout_toLeftOf="@+id/property_row_more_open"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true">
<include
android:id="@+id/property_row_price_row"
layout="@layout/PropertyListRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding_half" />
<include
android:id="@+id/property_row_lease_row"
layout="@layout/PropertyListRowPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding_half" />
<TextView
android:id="@+id/property_row_stats"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_medium"
android:textColor="@color/white"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding_half" />
<TextView
android:id="@+id/property_row_address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_address"
android:textColor="@color/white"
android:singleLine="true"
android:ellipsize="end"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding" />
<TextView
android:id="@+id/property_row_apn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_medium"
android:textColor="@color/white"
android:singleLine="true"
android:ellipsize="none"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:visibility="gone" />
<Button
android:id="@+id/property_row_comps_button"
android:layout_width="200dp"
android:text="Add to Comps"
style="@style/Widget.Button.Rounded.Blue.WhiteText"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding"
android:visibility="gone" />
</LinearLayout>
<RPR.Mobile.Droid.Widget.CachedImageView
android:id="@+id/property_row_more_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/property_row_more_off"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="@dimen/padding"
android:layout_marginBottom="@dimen/padding" />
<RPR.Mobile.Droid.Widget.CachedImageView
android:id="@+id/property_row_save_status"
android:layout_above="@+id/property_row_more_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/property_row_saved"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/padding"
android:layout_marginBottom="@dimen/padding" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/property_row_more_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:visibility="gone">
<LinearLayout
android:id="@+id/property_row_more_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/padding"
android:layout_marginLeft="@dimen/padding"
android:layout_marginRight="@dimen/padding">
<TextView
android:id="@+id/property_row_create_report"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/Widget.TextView.BlueText.DrawableTop"
android:background="@android:color/transparent"
android:drawableTop="@drawable/property_row_create_report_selector"
android:text="Create Report"
android:textColor="@color/blue" />
<TextView
android:id="@+id/property_row_save"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/Widget.TextView.BlueText.DrawableTop"
android:background="@android:color/transparent"
android:drawableTop="@drawable/property_row_save_selector"
android:text="Save Property"
android:textColor="@color/blue" />
<TextView
android:id="@+id/property_row_save_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/Widget.TextView.BlueText.DrawableTop"
android:background="@android:color/transparent"
android:drawableTop="@drawable/property_row_save_name_selector"
android:text="Add Custom Name"
android:textColor="@color/blue" />
</LinearLayout>
<LinearLayout
android:id="@+id/property_row_more_bottom"
android:layout_below="@+id/property_row_more_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="@dimen/padding"
android:layout_marginLeft="@dimen/padding"
android:layout_marginRight="@dimen/padding">
<TextView
android:id="@+id/property_row_add_note"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/Widget.TextView.BlueText.DrawableTop"
android:background="@android:color/transparent"
android:drawableTop="@drawable/property_row_add_note_selector"
android:text="Add Note / Photo"
android:textColor="@color/blue" />
<TextView
android:id="@+id/property_row_call_agent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
style="@style/Widget.TextView.BlueText.DrawableTop"
android:background="@android:color/transparent"
android:drawableTop="@drawable/property_row_call_agent_selector"
android:text="Call Agent"
android:textColor="@color/blue" />
<View
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:visibility="invisible" />
</LinearLayout>
<TextView
android:id="@+id/property_row_more_address"
android:layout_toLeftOf="@+id/property_row_more_close"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/search_list_item_text_size_address"
android:textColor="@color/blue"
android:singleLine="true"
android:ellipsize="end"
android:layout_alignParentBottom="true"
android:layout_marginLeft="@dimen/padding"
android:layout_marginBottom="@dimen/padding" />
<RPR.Mobile.Droid.Widget.CachedImageView
android:id="@+id/property_row_more_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/property_row_more_on"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="@dimen/padding"
android:layout_marginBottom="@dimen/padding" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>