Difference between src and background in android: androidsrc

Source: Internet
Author: User
Tags xml attribute

Difference between src and background in android: androidsrc
Differences between the XML Attribute src and background in ImageView:

Background is stretched Based on the length and width specified by the ImageView component, while src stores the source image size and does not stretch. Src is the image content (foreground), bg is the background, and can be used at the same time.

In addition, scaleType only applies to src; bg can set transparency. For example, in ImageButton, android: scaleType can be used to control the image scaling mode. 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"/>

Note: centerInside indicates scaling the image proportionally, so that the image length (width) is smaller than or equal to the corresponding dimension of the view.

Note: The controlled images are resources rather than backgrounds, that is, android: src = "@ drawable/logo", rather than android: background = "@ drawable/logo ". The dynamic loading of images in the program is similar, for example, imgView. setImageResource (R. drawable. *), rather than imgView. setBackgroundResource (R. drawable .*);


Appendix: More detailed scaleType description:

CENTER/center displays images in the view CENTER without scaling

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

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

FIT_CENTER/fitCenter scales the image proportionally to the smallest side of the view and is displayed in the center.

FIT_END/fitEnd scales the image proportionally to the smallest side of the view, which is displayed in the lower part of the view.

FIT_START/fitStart scales up or down an image proportionally to the smallest side of the view, which is displayed on the top of the view.

FIT_XY/fitXY: scale the image out of proportion to the view size.

MATRIX/matrix is drawn using a MATRIX.



What is the difference between android: src and android: background?

For ImageView:
You can set the background of the ImageView.
Android: src setting: This setting works when setAlpha () of ImageView is set.
Android: background setting: it does not work when setAlpha () of ImageView is set.

What is the difference between src and background of imagebutton?

ImageButton is a Button control with icons. It has the property of src, that is, setting its icon, and a public property background of all controls. You can also set its "icon ".
In fact, src is the setting icon, while background is only the setting background.
If the size of the control is 100*100, the image resource is 80*80, and src is used, the image is displayed in the center. If background is used, the image is stretched and filled with controls.
Importantly, the background is the underlying image resource, and the src is the resource that covers the background. They can be used in combination to achieve the selected effect. Used in ActivityGroup.
Hope to help you ~~

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.