Android Development ImageView Image scaling to achieve the method _android

Source: Internet
Author: User

This article is an example of how the Android development ImageView image scaling is implemented. Share to everyone for your reference, specific as follows:

Android:scaletype controls how the picture is scaled, as shown in the sample code:

<imageview android:id= "@+id/img" 
  android:src=\ ' #\ ' "/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 control of the picture is a resource rather than a background, that is, android:src=\ ' #\ ' "/logo" rather than android:background= "@drawable/logo", I was stupid to make this low-level mistake, Lead to the wrong people scaletype not work. Dynamic loading of the picture in the program is similar, such as: Should 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

I hope this article will help you with the Android program.

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.