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

What is the difference between src and background?

yulia
Release: 2018-09-21 17:37:18
Original
3670 people have browsed it

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"/>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template