我需要在左侧有一些带有可绘制的文本,并且我想在用户单击/触摸图像时执行一些代码(只有图像,而不是文本),所以我使用了带有TextView和ImageView的LinearLayout可点击并启动 onClick 事件。XML 解析器建议我用带有复合 drawable的TextView替换它,这将用更少的XML行绘制相同的东西。我的问题是“我可以指定我只想在 drawable 上处理 onClick 事件TextView而不是TextView本身?我见过一些解决方案,其中涉及编写自己的TextView扩展,但如果可能的话,我只对能够在布局资源中执行此操作感兴趣,否则我将保留以下XML代码:
<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="bottom"
            android:paddingTop="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:text="@string/home_feedback_title"
            android:textColor="@android:color/primary_text_dark"
            android:textStyle="bold" 
            android:paddingBottom="4dp"/>
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/action_feedback" 
            android:clickable="true"
            android:onClick="onClickFeedback"
            android:contentDescription="@string/action_feedback_description"/>
</LinearLayout>