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.
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.
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.
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.
ImageView class is used to display any kind of image resource in the android application either it can be android. graphics. Bitmap or android.
All views can take a background image.
The src
to an ImageView
has additional features:
adjustViewBounds
for setting bounds to match image dimensionsAnd more that you may find in the docs.
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
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With