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.