Android implements ImageView compression and solves the problem of applying for background images,
Create a. 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"/> // press chip 5 <item android: state_enabled = "true" android: drawable = "@ drawable/image"/> // picture 6 not pressed </selector>
Then set the src of the image ImageView to @ drawable/image_tab_bg.
Note: Do not set it to the Background attribute of ImageView. In this way, the image will be rejected.
Differences between the XML Attribute src and background in ImageView:
Background is stretched Based on the length and width specified by the ImageView component, while src stores the source image size and does not stretch. Src is the image content (foreground), bg is the background, and can be used at the same time.
In addition, scaleType only applies to src; bg can set transparency. For example, android: scaleType can be used in ImageButton to control the image scaling mode.