The difference between SRC and background in Android _android

Source: Internet
Author: User
Tags xml attribute

The difference between XML attribute src and background in ImageView:

The background will stretch according to the length given by the ImageView component, and SRC will hold the size of the original image without stretching. SRC is the picture content (foreground), BG is the background, 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 how the image is scaled, sample code 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 represents scaling the picture so that the length (width) of the picture is less than the corresponding dimension of the view.

Note: The controlled picture is a resource rather than a background, i.e. android:src= "@drawable/logo" rather than android:background= "@drawable/logo". Dynamic loading of pictures in the program is similar, such as: Should be Imgview.setimageresource (r.drawable.*), rather than Imgview.setbackgroundresource (r.drawable.*);

Attached: More detailed ScaleType Description:

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

Center_crop/centercrop scale the picture so that the picture is longer (wider) than the corresponding dimension that is equal to the view

Center_inside/centerinside scale the picture so that the length (width) of the picture is less than or equal to the corresponding dimension of the view

Fit_center/fitcenter scale the picture to the smallest side of the view, centered

Fit_end/fitend scale the picture to the smallest side of the view, displayed in the lower part of the view

Fit_start/fitstart enlarge/Shrink the picture to the smallest side of the view, showing in the upper part of the view

Fit_xy/fitxy The picture is not scaled to the view size display

Matrix/matrix using matrices to draw

The above is to the Android SRC and background differences in the collation of information, follow-up continue to supplement the relevant information, thank you for your support for this site!

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.