[ACCEPTED]-What is the difference between src and background of ImageView-src

Accepted answer
Score: 78

All views can take a background image.

The 2 src to an ImageView has additional features:

  • different scaling types
  • adjustViewBounds for setting bounds to match image dimensions
  • some transformations such as alpha-setting

And more 1 that you may find in the docs.

Score: 24
  1. when you use android:background, image will be set to fit 5 on ImageView area(i.e according to width and height 4 of ImageView). It doesn't matter if the image is 3 smaller or larger than ImageView.

  2. when you use android:src, then 2 image will display in its original size. No automatic 1 scaling, adjustments will happen.

Score: 22

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.

Score: 3

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:

  android:layout_width= "60dip"
  android:layout_centerVertical= "true"/>

Feel free to ask doubt if 1 you get any.

More Related questions