[ACCEPTED]-What is the difference between src and background of ImageView-src
All views can take a background image.
src to an
ImageView has additional features:
- different scaling types
adjustViewBoundsfor setting bounds to match image dimensions
- some transformations such as alpha-setting
And more 1 that you may find in the docs.
when you use
android:background, image will be set to fit 5 on
ImageViewarea(i.e according to width and height 4 of
ImageView). It doesn't matter if the image is 3 smaller or larger than
when you use
android:src, then 2 image will display in its original size. No automatic 1 scaling, adjustments will happen.
If you set an image to be the background 5 of your ImageView, then the image will scale 4 to whatever size the ImageView is. Other 3 than that, src is a foreground image and 2 background is a background image. Pretty 1 much as it implies.
The difference between XML attribute src and background in ImageView:
The background will stretch according to 9 the length given by the ImageView component, and 8 SRC will hold the size of the original image 7 without stretching. SRC is the picture content 6 (foreground), BG is the background, can be 5 used at the same time.
In addition: ScaleType only works on SRC; BG can 4 set transparency, for example, in ImageButton, you can use Android:scaletype to 3 control how the image is scaled, sample 2 code as follows:
<ImageView android:id="@+id/img" android:layout_height="60dip" android:layout_width= "60dip" android:src="@drawable/logo" android:scaleType="centerInside" android:layout_centerVertical= "true"/>
Feel free to ask doubt if 1 you get any.
More Related questions