Differences between src and background in android
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, in ImageButton, android: scaleType can be used to control the image scaling mode. The sample code is as follows:
Android: src = "@ drawable/logo"
Android: scaleType = "centerInside"
Android: layout_width = "60dip"
Android: layout_height = "60dip"
Android: layout_centerVertical = "true"/>
Note: centerInside indicates scaling the image proportionally, so that the image length (width) is smaller than or equal to the corresponding dimension of the view.
Note: The controlled images are resources rather than backgrounds, that is, android: src = "@ drawable/logo", rather than android: background = "@ drawable/logo ". The dynamic loading of images in the program is similar, for example, imgView. setImageResource (R. drawable. *), rather than imgView. setBackgroundResource (R. drawable .*);
Appendix: More detailed scaleType description:
CENTER/center displays images in the view CENTER without scaling
CENTER_CROP/centerCrop scales the image proportionally so that the image length (width) is greater than or equal to the corresponding dimension of the view.
CENTER_INSIDE/centerInside scales the image proportionally so that the image length (width) is smaller than or equal to the corresponding dimension of the view.
FIT_CENTER/fitCenter scales the image proportionally to the smallest side of the view and is displayed in the center.
FIT_END/fitEnd scales the image proportionally to the smallest side of the view, which is displayed in the lower part of the view.
FIT_START/fitStart scales up or down an image proportionally to the smallest side of the view, which is displayed on the top of the view.
FIT_XY/fitXY: scale the image out of proportion to the view size.
MATRIX/matrix is drawn using a MATRIX.