Roid imageView proportional Scaling

Source: Internet
Author: User


Android: scaleType controls the scaling mode of images. The sample code is as follows:

1 <ImageView android:id="@+id/img"
2 android:src="@drawable/logo"
3 android:scaleType="centerInside"
4 android:layout_width="60dip"
5 android:layout_height="60dip"
6 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", not android: background = "@ drawable/logo ", I am stupid enough to make this low-level mistake, causing scaleType to be ineffective. The dynamic loading of images in the program is similar, for example, imgView. setImageResource (Integer) mData. get (position ). get ("img"); not imgView. setBackgroundResource (Integer) mData. get (position ). get ("img "));

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.

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.