我遇到了这个问题,我之前看过你的问题,这里我做了什么并且工作得很好:
您可以使用该FrameLayout
android:foreground
属性为您完成工作
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:descendantFocusability="afterDescendants"
android:duplicateParentState="true"
android:focusable="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:descendantFocusability="beforeDescendants"
android:focusable="true"
android:focusableInTouchMode="true"
android:foreground="@drawable/draw_on_top_selector">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#282828"
android:paddingBottom="5dp">
<ImageView
android:layout_width="160dp"
android:layout_height="90dp"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_gravity="center_vertical|center_horizontal"
android:adjustViewBounds="true"
android:contentDescription="@string/app_name"
android:scaleType="centerCrop"
android:src="@drawable/video_blank" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/episodeImage"
android:layout_alignLeft="@id/episodeImage"
android:background="@android:color/black"
android:gravity="right"
android:padding="2dp"
android:textColor="#FFFFFF"
android:textSize="11sp" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
draw_on_top_selector.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/show_cell_background_selected" android:state_pressed="true"/>
<item android:drawable="@drawable/show_cell_background"/>
</selector>
show_cell_background_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:width="4dp"
android:color="#FFD900" >
</stroke>
<solid android:color="@android:color/transparent" />
</shape>
</item>
</layer-list>
show_cell_background.xml
<?xml version="1.0" encoding="UTF-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
<shape android:shape="rectangle" >
<stroke
android:width="2dp"
android:color="#20000000" >
</stroke>
<solid android:color="@android:color/transparent" />
</shape>
</item>
</layer-list>