Build one. XML file, named: Image_tab_bg.xml
1 <?xml version= "1.0" encoding= "Utf-8"?>2 <selector3 xmlns: Android= "Http://schemas.android.com/apk/res/android" >4 <item android:state_pressed= "true" android:drawable= "@drawable/image_press"/>//down slice 5 <item android:state_enabled= "true" Android: drawable= "@drawable/image"/> //not pressed for picture 6 7 </selector>
Then you want to implement the picture ImageView SRC set to: @drawable/IMAGE_TAB_BG can
Note: Do not set the background attribute to ImageView, so the picture will be Lachen
The difference between the XML attribute src and background in ImageView:
The background is stretched according to the length and width given by the ImageView component, while SRC stores the size of the original and does not stretch. SRC is the picture content (foreground), BG is the background and can be used simultaneously.
In addition: ScaleType only works on SRC; BG can set transparency, such as the ability to use Android:scaletype to control how images are scaled in ImageButton
Android achieves imageview compressions and resolves background image lachen issues