???????¦Ë??: ??????? > Android > android??? >
|??????:???|????|????|???|????

Android?????ImageView?????????????????????

???:2012-10-29 ???:??????? ???: ??

?????ImageView??????????????????????????¡ê?????????????§¹???????§»?????????????????????????????????????????????res/drawable??????¡ä??????xml?????????my.xml,???????¡ê?

  1. <?xml version="1.0" encoding="utf-8"?>  
     
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
     
  3.     <item android:state_pressed="true"  
     
  4.         android:drawable="@*android:drawable/btn_search_dialog_voice_pressed" />  
     
  5.     <item android:state_pressed="false"  
     
  6.         android:drawable="@*android:drawable/btn_search_dialog_voice_default" />  
     
  7. </selector>  
???????

????????????????????????drawable????????????????????????????????????????????????

  1. android:drawable="@drawable/ic_desk_point_normal"  
???????

????????imageView??xml????????????

  1. android:src="@drawable/youPicture"  
     
  2. android:background="@drawable/my"  
???????

??????????§¹????

 

???????XML?????.xml?????????list_item_bg.xml????????????????ListView???§Ò???????????????????????

drawable/list_item_bg.xml

  1. <?xml version="1.0" encoding="utf-8" ?>     
     
  2. <selector xmlns:android="http://schemas.android.com/apk/res/android">  
     
  3.   <!-- ??????????? -->   
     
  4.   <item android:drawable="@drawable/pic1" />  
     
  5.    
     
  6.   <!-- ??§ß??????????? -->   
     
  7.   <item android:state_window_focused="false"   
     
  8.         android:drawable="@drawable/pic1" />     
     
  9.    
     
  10.   <!-- ??????????y??????????????? -->   
     
  11.   <item android:state_focused="true" android:state_pressed="true"     
     
  12.         android:drawable= "@drawable/pic2" />   
     
  13.    
     
  14.   <!-- ???????¦Ì??????????? -->   
     
  15.   <item android:state_focused="false" android:state_pressed="true"     
     
  16.         android:drawable="@drawable/pic3" />     
     
  17.    
     
  18.   <!--????????????  -->   
     
  19.   <item android:state_selected="true"     
     
  20.         android:drawable="@drawable/pic4" />     
     
  21.    
     
  22.   <!--??y????????????  -->   
     
  23.   <item android:state_focused="true"     
     
  24.         android:drawable="@drawable/pic5" />     
     
  25. </selector>  
???????

??¡Â???

  • ?????????listview??????android:listSelector=”@drawable/list_item_bg”
  • ?????????listview??item?????????android:background=”@drawable/list_item_bg”
  • ????????java??????????Drawable drawable = getResources().getDrawable(R.drawable.list_item_bg);listview.setSelector(drawable);
     

????§Ò??????????????????????????????????????

android:cacheColorHint="@android:color/transparent"

?????????|???????????|??????¦Ã???|??XML???