1 需要實現的效果:
業務需要實現,選擇圖片的效果。
實現的效果圖:

2解決思路:
利用 ImageView 控件中的background屬性和padding屬性,在圖片外面顯示邊框,並通過控件的狀態,更改邊框的背景,實現點擊效果
3 實戰代碼:
<ImageView
android:id="@+id/img_1"
android:adjustViewBounds="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="4dp"
android:focusable="true"
android:clickable="true"
android:tag="1"
android:background="@drawable/imgselect"
android:src="@drawable/sl1_1" />
imgselect (drawable)
<?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/img_on" />
<item android:state_pressed="true" android:drawable="@drawable/img_on" />
<item android:drawable="@drawable/img_off" />
</selector>
