一、我的項目的案例情況:不知道,大家有沒有遇到過這種情況,在ToolBar導(dǎo)航欄里,通常都有,這樣一個back圖標(biāo),用于返回上一級頁面,但是如果你用imageView來顯示這個圖標(biāo),它經(jīng)常會出現(xiàn),點擊了,但是沒反應(yīng),需要點擊多次才有反應(yīng)。
返回鍵.PNG
那是什么原因造成的呢?
原因及時很簡單,
如果你的布局是這樣的
<ImageView
android:id="@+id/back_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:contentDescription="@null"
android:scaleType="centerCrop"
android:src="@drawable/arrowl"/>
那就會造成點擊事件,時靈時不靈的情況。原因很簡單,就是ImageView
所占的區(qū)域太小了,導(dǎo)致手指的點擊事件經(jīng)常不能被感知
解決辦法也很簡單、把ImageView換成ImageButton,增加一點padding,把背景改成透明就行,就可以擴大這個返回圖標(biāo)的覆蓋區(qū)域了
<!--返回鍵-->
<ImageButton
android:id="@+id/back_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="20dp"
android:contentDescription="@null"
android:scaleType="centerCrop"
android:src="@drawable/arrowl"
android:background="@color/transparent"/>