2017-09-14 35 views

回答

2

如果您覆盖boolean onTouch(View v, MotionEvent event),我相信这是可能的。不过,实际上,如果您将ImageView的搜索图标放在EditText的右侧,并且只需点击ImageView即可实现。

<RelativeLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content"> 
    <EditText 
     android:layout_toLeftOf="@id/search" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" /> 
    <ImageView 
     android:id="@+id/search" 
     android:layout_alignParentRight="true" 
     android:layout_width="wrap_content" 
     android:src="@android:drawable/ic_search_category_default" 
     android:layout_height="wrap_content" /> 
</RelativeLayout> 
+0

onTouch的问题是要知道要计数的区域,而不是将其与文本重叠。这正确的答案是这样的。 –

+0

你总是可以添加正确的填充以确保文本不会覆盖图像...但它仍然不是我推荐的模式:) – Jon

+0

谢谢@GabeSechan是不是只能使图标的可点击部分成为可能(这是9个补丁映像的非可缩放部分)? – hereForLearing