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
Solutions for reference
Toolbar_bg_selector.xml:
- <? XML version= "1.0" encoding="Utf-8"?>
- <selector xmlns:android="http://schemas.android.com/apk/res/android" >
- <item android:state_pressed="true" >
- <bitmap android:src="@drawable/toolbar_bg_sel" android:tilemode="Disabled " android:gravity="Top" />
- </Item>
- <item >
- <bitmap android:src="@drawable/toolbar_bg" android:tilemode="disabled" Android: gravity="Top" />
- </Item>
- </selector>
Resolve Android:background background picture is stretched