2017-09-14 17 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

相關問題