What is the difference between src and background

2019-01-06 12:40发布

I am a little puzzled with 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 detect which one to use? I don't see the difference.

3条回答
Lonely孤独者°
2楼-- · 2019-01-06 13:12

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.

查看更多
▲ chillily
3楼-- · 2019-01-06 13:12

If you set an image to be the background of your ImageView, then the image will scale to whatever size the ImageView is. Other than that, src is a foreground image and background is a background image. Pretty much as it implies.

查看更多
贪生不怕死
4楼-- · 2019-01-06 13:24
  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.

查看更多
登录 后发表回答