What is the difference between src and background?
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



How to use CSS to implement rotating background image animation effects of elements. Background image animation effects can increase the visual appeal and user experience of web pages. This article will introduce how to use CSS to achieve the rotating background animation effect of elements, and provide specific code examples. First, we need to prepare a background image, which can be any picture you like, such as a picture of the sun or an electric fan. Save the image and name it "bg.png". Next, create an HTML file and add a div element in the file, setting it to

src and href are respectively, 1. src is the abbreviation of source, which is used to specify the path of external resources. It is usually used to embed external files, such as pictures, audios, videos, etc. The src attribute is generally used on img, script, iframe and other tags. ; 2. href is the abbreviation of hypertext reference, which is used to specify the path of the target resource of the hyperlink. It is usually used to link to external documents or other pages. The href attribute is generally used on tags such as a and link.

The src attribute and href attribute are commonly used attributes in HTML and are used to load external resources. Although they have similar purposes, there are some differences in usage and purpose. src attribute: The src attribute is used to specify external resources to be embedded in the document. It is mainly used to introduce external script files and media files into HTML documents. It can be used in the following situations: Introduce external JavaScript files: Link external JavaScript files to HTML pages through the src attribute.

Get requests sent by href and src. Detailed description: 1. The href attribute is used to specify the target resource of the link. When referencing an external style sheet, it will send a GET request to obtain the CSS file. When referencing the document, it will send a GET request to obtain the specified HTML file. When referencing an image, it will send a GET request. To obtain the specified image file; 2. The src attribute is used to specify the URL of the embedded resource. When referencing the image, it will send a GET request to obtain the specified image file. When referencing the audio, it will send a GET request to obtain the specified audio file, etc. .

What is the difference between src and href? Find out quickly! In the process of web development, src and href are two commonly used attributes. Although they look similar, they actually have different uses and applicable scenarios. In this article, we’ll dive into the differences between src and href and explain them with concrete code examples. In HTML, src is an attribute used to specify an external resource to be embedded or referenced. It is usually used to reference image, audio, video or script files. Unlike this, href is a hyperlink

The difference between src and href, details you must know! When writing HTML pages, we often encounter the two attributes src and href. They are both used to reference external resources, such as script files, style files, or images. Although their purposes are similar, there are some differences in their specific usage and details. First of all, the src (source) attribute is mainly used to embed external resources, such as pictures or scripts. It is used to specify the address of a resource and embed its content into the current document. And href(

What are src attributes and href attributes? What's the difference between them? In HTML, the src attribute and the href attribute are two commonly used attributes for referencing external resources. Although they are somewhat similar in functionality, there are some differences in usage and types of referenced resources. First, let's take a look at the src attribute. src is the abbreviation of source, which is mainly used to specify the address of embedding/referencing external resources. It can be applied to some tags such as <script>, <img>

Both the src and href attributes are used to specify the address of the resource, but the purposes and usage scenarios are different: 1. The src attribute is used to specify the address of the external resource, while the href attribute is used to specify the target address of the hyperlink; 2. The src attribute is introduced It is used when media elements are used, and the href attribute is usually used in the <a> tag; 3. The src attribute tells the browser to load the specified resource and embed it into the current page, and the href attribute defines the web page to be opened after the user clicks , document, or other resource URL.
