2011-09-06 96 views

回答

0

您可以在gridview中的圖像周圍留下邊距,然後在觸摸佈局時,可以爲可點擊的圖像設置不同的背景顏色。

+0

非常感謝,這似乎是一個更簡單的方法。我會嘗試一下,看看 –

0

你需要創造兩個影像一爲正常模式(button)和第二選定模式(button_selected)..

後,然後創建一個XML等作爲selectable.xml並把它繪製文件夾

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:state_focused="true" android:state_pressed="false" 
     android:drawable="@drawable/button" /> 
    <item android:state_focused="true" android:state_pressed="true" 
     android:drawable="@drawable/button" /> 
    <item android:state_focused="false" android:state_pressed="true" 
     android:drawable="@drawable/button_selected" /> 
    <item android:drawable="@drawable/button" /> 
</selector> 

後,然後在您的ImageView的背景將此XML

等作爲

android:background="@drawable/selectable" 
+0

謝謝。我正在尋找一個解決方案,我不必爲不同的狀態保留不同的圖像。非常感謝 –