The difference between XML attribute src and background in ImageView:
The background will stretch according to the length given by the ImageView component, and SRC will hold the size of the original image without stretching. SRC is the picture content (foreground), BG is the background, can be used at the same time.
In addition: ScaleType only works on SRC; BG can set transparency, for example, in ImageButton, you can use Android:scaletype to control how the image is scaled, sample code as follows:
<imageview android:id= "@+id/img"
android:src= "@drawable/logo
" android:scaletype= "Centerinside" Android:layout_width= "60dip"
android:layout_height= "60dip"
android:layout_centervertical= "true"/>
Description: Centerinside represents scaling the picture so that the length (width) of the picture is less than the corresponding dimension of the view.
Note: The controlled picture is a resource rather than a background, i.e. android:src= "@drawable/logo" rather than android:background= "@drawable/logo". Dynamic loading of pictures in the program is similar, such as: Should be Imgview.setimageresource (r.drawable.*), rather than Imgview.setbackgroundresource (r.drawable.*);
Attached: More detailed ScaleType Description:
Center/center displays a picture in the center of the view and does not scale the picture
Center_crop/centercrop scale the picture so that the picture is longer (wider) than the corresponding dimension that is equal to the view
Center_inside/centerinside scale the picture so that the length (width) of the picture is less than or equal to the corresponding dimension of the view
Fit_center/fitcenter scale the picture to the smallest side of the view, centered
Fit_end/fitend scale the picture to the smallest side of the view, displayed in the lower part of the view
Fit_start/fitstart enlarge/Shrink the picture to the smallest side of the view, showing in the upper part of the view
Fit_xy/fitxy The picture is not scaled to the view size display
Matrix/matrix using matrices to draw
The above is to the Android SRC and background differences in the collation of information, follow-up continue to supplement the relevant information, thank you for your support for this site!