Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between src and background of ImageView

I am a puzzled about using src or background for an ImageView.

I know the former means the content of this ImageView and the latter means the background of the ImageView.

But how to decide which one to use? I don't see the difference.

like image 373
peter_feng Avatar asked Mar 28 '11 03:03

peter_feng


People also ask

What is difference between SRC and background in Android?

All views can take a background image. The src to an ImageView has additional features: different scaling types. adjustViewBounds for setting bounds to match image dimensions.

What is SRC in ImageView?

android:scaleType. Controls how the image should be resized or moved to match the size of this ImageView. android:src. Sets a drawable as the content of this ImageView.

What is difference between ImageView and ImageButton?

ImageButton has the same property as ImageView . Only one feature is extra, which is, images set through ImageButton are clickable, and actions can be attached with them upon clicking. Just like a button, the setOnClickListener() can be used to set an event listener for click event on this.

What is the use of ImageView?

ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android.


2 Answers

All views can take a background image.

The 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 that you may find in the docs.

like image 129
Matthew Willis Avatar answered Sep 25 '22 05:09

Matthew Willis


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

  2. when you use android:src, then image will display in its original size. No automatic scaling, adjustments will happen. Note: Using android:src, we can get additional benefit of adjustViewBounds property

like image 41
Ketan Patel Avatar answered Sep 25 '22 05:09

Ketan Patel