ScaleType attribute of android ImageView, imageviewscaletype
ImageView. setScaleType (ImageView. ScaleType. FIT_XY );
Here we will focus on understanding the attributes of ImageView android: scaleType, that is, ImageView. setScaleType (ImageView. ScaleType ). Android: scaleType controls how images are resized/moved to match the size of ImageView. ImageView. ScaleType/android: the differences between scaleType values:
CENTER/center is centered according to the original size of the image. When the length/width of the image exceeds the length/width of the View, the CENTER part of the captured image is displayed.
CENTER_CROP/centerCrop scales up the image size in the center, so that the image length (width) is equal to or greater than the View length (width)
CENTER_INSIDE/centerInside shows the entire content of the image in the center. The image length/width is equal to or less than the View length/width by proportional reduction or the original size.
FIT_CENTER/fitCenter scales up/down the image proportionally to the width of the View and center the image.
FIT_END/fitEnd: scales up or down an image to the width of the View, which is displayed in the lower part of the View.
FIT_START/fitStart scales up/down an image proportionally to the width of the View.
FIT_XY/fitXY increase or decrease the image size proportionally to the View size.
MATRIX/matrix is drawn using a MATRIX.
// Obtain the height and width of Bitmap
Int bmp width = bmp. getWidth ();
Int bmpHeight = bmp. getHeight ();
// Set the scale-down ratio
Double scale = 0.8;
// Calculate the proportion to be reduced this time
ScaleWidth = (float) (scaleWidth * scale );
ScaleHeight = (float) (scaleHeight * scale );
// Generate the Bitmap object after resize
Matrix matrix = new Matrix ();
Matrix. postScale (scaleWidth, scaleHeight );
Bitmap resizeBmp = Bitmap. createBitmap (bmp, 0, 0, bmp width, bmpHeight, matrix, true );
ScaleType attributes include: matrix fitXY fitStart fitCenter fitEnd center centerCrop centerInside
The differences between them are as follows:
Matrix is drawn using a matrix (from the upper left corner of the matrix Area)
FitXY scales up or down the image to the View size (make sure the image is fully displayed and full of View)
FitStart scales up/down an image to the width of the View, and displays the image in the top part of the View (the image will be completely displayed)
FitCenter scales up/down the image to the width of the View in proportion and center the image (the image is displayed completely)
FitEnd scales up/down the image to the width of the View, and displays the image in the lower part of the View)
Center is centered by the original size of the image. When the image width exceeds the View width, the center part of the screenshot is displayed. If the image width is smaller than the View width, the image is centered.
CenterCrop scales up or down the image size in the center, so that the image height is equal to the View height, so that the image width is equal to or greater than the View width.
CenterInside shows the entire content of the image in the center so that the image is scaled down proportionally or the original size (the image is smaller than the View hour) so that the image width is equal to or less than the View width (the image will be fully displayed)