Home  >  Article  >  Web Front-end  >  What is the difference between src and background?

What is the difference between src and background?

yulia
yuliaOriginal
2018-09-21 17:37:183637browse

We all know that if we want to add pictures to the page, we can use src or background. Then we can add pictures to both of them. What is the difference between them? Next, I will talk to you about the difference between src and background. Friends who are interested can take a look. Welcome to like and comment.

The difference between the XML attributes src and background in ImageView:

Background will stretch according to the length and width given by the ImageView component, while src The size of the original image is stored and will not be stretched. src is the image content (foreground), and bg is the background, which can be used at the same time.

In addition: scaleType only works on src; bg can set transparency. For example, in ImageButton, you can use android:scaleType to control the zoom mode of the image. The sample code is as follows:

<ImageView android:id="@+id/img"?
android:src="@drawable/logo"
android:scaleType="centerInside"
android:layout_width="60dip"
android:layout_height="60dip"
android:layout_centerVertical="true"/>

Description: centerInside Indicates scaling the picture proportionally so that the length (width) of the picture is less than or equal to the corresponding dimension of the view.

Note: The controlled image is a resource rather than a background, that is, android:src="@drawable/logo", not android:background="@drawable/logo". The dynamic loading of images in the program is also similar, such as: imgView.setImageResource(R.drawable.*); instead of imgView.setBackgroundResource(R.drawable.*)

Attachment: More detailed scaleType description:

CENTER /center displays the picture in the center of the view and does not scale the picture

CENTER_CROP/ centerCrop scales the picture proportionally so that the length? (width) of the picture is greater than or equal to the corresponding dimension of the view

CENTER_INSIDE/ centerInside scales the picture proportionally so that the length (width) of the picture is less than or equal to the corresponding dimension of the view

FIT_CENTER/ fitCenter scales the picture proportionally to the smallest side of the view and displays it in the center

FIT_END/ fitEnd scales the picture proportionally to the smallest side of the view, and displays it in the lower part of the view

FIT_START/ fitStart scales the picture proportionally to the smallest side of the view, and displays it in the upper part of the view

FIT_XY/ fitXY Scale the picture to the size of the view without proportional display

MATRIX/ matrix Use matrix to draw

The above is the detailed content of What is the difference between src and background?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn