Android 在RecyclerView中作为动作的可拉伸复合材料

Android 在RecyclerView中作为动作的可拉伸复合材料,android,android-layout,android-drawable,android-recyclerview,Android,Android Layout,Android Drawable,Android Recyclerview,我有一个RecyclerView,它实现了字符串项的线性列表。 我希望列表项在每个项的右侧有一个辅助操作“共享”。我创建了一个类似Google建议的XML复合可绘制文件,但如何访问该可绘制文件并在其上设置OnClickListener()?只有两种元素对我更好吗 我的列表项布局中的复合可绘制文本视图: <TextView android:id="@+id/item" android:layout_width="match_parent" android:layout

我有一个RecyclerView,它实现了字符串项的线性列表。 我希望列表项在每个项的右侧有一个辅助操作“共享”。我创建了一个类似Google建议的XML复合可绘制文件,但如何访问该可绘制文件并在其上设置
OnClickListener()
?只有两种元素对我更好吗

我的列表项布局中的复合可绘制文本视图:

<TextView
    android:id="@+id/item"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/text_margin"
    android:textSize="17sp"
    android:layout_marginTop="1dp"
    android:background="#101010"
    android:drawableRight="@drawable/ic_share_white_24dp"
    android:textColor="#fff"
    android:textAppearance="?attr/textAppearanceListItem" />

得到了一些很好的建议,但对于我的项目,尤其是我发现有两个元素可以更好地进行管理。请查看@Vishnuvathsan对化合物可拉伸材料的回答

<TextView
    android:id="@+id/content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="@dimen/text_margin"
    android:textSize="17sp"
    android:layout_marginTop="1dp"
    android:background="#101010"
    android:textColor="#fff"
    android:textAppearance="?attr/textAppearanceListItem" />
<ImageView
    android:id="@+id/shareBtn"
    android:contentDescription="@string/action_share"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:padding="6dp"
    android:src="@drawable/ic_share_white_24dp"
    android:background="#101010"
    android:layout_centerVertical="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true" />

最好有两个不同的元素。请检查此项