The ImageView class can load images from various sources (such as resources or image libraries). You need to calculate the size of the image, so it can be used in other la S and provide such scaling and coloring (rendering) various display options.
<1>
Attribute
Description of the method corresponding to the property name
Android: adjustViewBounds setAdjustViewBounds (boolean)
If this attribute is set to true, the image aspect ratio can be maintained when the ImageView border is adjusted. (It must be used with maxWidth and MaxHeight; otherwise, it will not work if it is used separately .)
Android: baseline setBaseline (int)
Offset of the baseline in the view
Android: baselineAlignBottom setBaselineAlignBottom (boolean)
If true, the image view alignment the baseline with the bottom edge of the parent control.
Android: cropToPadding: if it is true, the image will be cut to adapt to the padding size.
Android: maxHeight setMaxHeight (int) provides an optional parameter for the maximum height of a view.
Android: maxWidth setMaxWidth (int)
Provides an optional parameter for the maximum width of a view.
Android: scaleType setScaleType (ImageView. ScaleType) controls how to change the image size or move the image to fit the ImageView size.
Android: src setImageResource (int)
Set the printable object as the display content of ImageView
Android: tint setColorFilter (int, PorterDuff. Mode)
<2>
Method:
Public void setMaxHeight (int maxHeight)
Optional parameter used to set the maximum height supported by the view. Valid only when setAdjustViewBounds (boolean) is true. To set the maximum image size to 100x100 and keep the original ratio, follow these steps:
1) set adjustViewBounds to true;
2) Set maxWidth and maxHeight to 100;
3) set the layout parameter to WRAP_CONTENT.
Note: If the original image is small, even if this parameter is set, the image is still smaller than 100x100. If you want to set the image size to a fixed value, you must specify the size in the layout parameter, and use the setScaleType (ImageView. ScaleType) function to detect how to adjust it to an appropriate size.
Parameters
MaxHeight: the maximum height of the view.
XML attributes
Android: maxHeight
Public void setMaxWidth (int maxWidth)
Optional parameter used to set the maximum width supported by the view. Valid only when setAdjustViewBounds (boolean) is true. To set the maximum image size to 100x100 and keep the original ratio, follow these steps:
4) set adjustViewBounds to true;
5) set maxWidth and maxHeight to 100;
6) set the layout parameter to WRAP_CONTENT.
Note: If the original image is small, even if this parameter is set, the image is still smaller than 100x100. If you want to set the image size to a fixed value, you must specify the size in the layout parameter, and use the setScaleType (ImageView. ScaleType) function to detect how to adjust it to an appropriate size.
Parameters
MaxWidth: the maximum width of the view.
XML attributes
Android: maxWidth
Public void setScaleType (ImageView. ScaleType scaleType)
Controls how images are scaled and moved to make them consistent with ImageView.
Parameters
ScaleType.
XML attributes
Android: scaleType
Public void setSelected (boolean selected)
Changes the selected view status. The view has two states: Selected and not selected. Note that the selection status is different from the focus. A typical selected view is the content displayed in AdapterView such as ListView and GridView. The selected content is highlighted.
Parameters
If selected is true, the view is set to the selected state; otherwise, the view is false.
Public void setImageURI (Uri uri)
Set the specified URI to the content displayed in the ImageView.
This operation reads bitmap and decodes it in the UI thread, which may lead to slow response. If the response is slow, use setImageDrawable (Drawable), setImageBitmap (Bitmap), or BitmapFactory.
Parameters
The uri Of The URI image.
Public void setImageBitmap (Bitmap bm)
Set bitmap as the ImageView content.
Parameters
The bitmap set by bm.
Public void setImageDrawable (Drawable drawable)
Set the printable object to the content displayed in the ImageView.
Parameters
The callable object set by drawable.
Public void setAdjustViewBounds (boolean adjustViewBounds)
When you need to adjust the border of ImageView to maintain the ratio of the printable object, set this value to true.
Parameters
Whether adjustViewBounds adjusts the border to maintain the original proportion of the object that can be drawn.
XML attributes
Android: adjustViewBounds
Public void setAlpha (int alpha)
Set transparency
<3>
ScaleType attributes:
Public static final ImageView. ScaleType CENTER
Center the image in the view without scaling. Syntax available in XML: android: scaleType = "center ".
Public static final ImageView. ScaleType CENTER_CROP
Balanced scaling of the image (maintaining the original image proportion), so that the two coordinates (width and height) of the image are greater than or equal to the corresponding View coordinates (negative padding ). The image is located in the center of the view. Syntax that can be used in XML: android: scaleType = "centerCrop ".
Public static final ImageView. ScaleType CENTER_INSIDE
Balanced scaling of the image (maintaining the original image proportion), so that the two coordinates (width and height) of the image are less than or equal to the corresponding View coordinates (negative padding ). The image is located in the center of the view. The syntax that can be used in XML: android: scaleType = "centerInside ".
Public static final ImageView. ScaleType FIT_CENTER
Use the CENTER Method to scale the image. Syntax available in XML: android: scaleType = "fitCenter ".
Public static final ImageView. ScaleType FIT_END
Use the END method to scale the image. The syntax that can be used in XML: android: scaleType = "fitEnd ".
Public static final ImageView. ScaleType FIT_START
Use the START method to scale the image. The syntax that can be used in XML: android: scaleType = "fitStart ".
Public static final ImageView. ScaleType FIT_XY
Use FILL to scale the image. The syntax that can be used in XML: android: scaleType = "fitXY ".
Public static final ImageView. ScaleType MATRIX
The image matrix is used to scale the image. The image Matrix can be set through setImageMatrix (Matrix. The syntax that can be used in XML: android: scaleType = "matrix ".
Case:
<? Xml version = "1.0" encoding = "UTF-8"?>
<LinearLayout xmlns: android = "http://schemas.android.com/apk/res/android"
Android: layout_width = "fill_parent"
Android: layout_height = "fill_parent"
Android: orientation = "vertical">
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "scaleType: fitXY"/>
<ImageView
Android: id = "@ + id/image1"
Android: adjustViewBounds = "true"
Android: layout_width = "300dp"
Android: layout_height = "100dp"
Android: src = "@ drawable/macos01"
Android: scaleType = "fitXY"
Android: background = "# F00"/>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "scaleType: center"/>
<ImageView
Android: id = "@ + id/image2"
Android: adjustViewBounds = "true"
Android: layout_width = "300dp"
Android: layout_height = "100dp"
Android: src = "@ drawable/macos04"
Android: scaleType = "center"
Android: background = "# F00"/>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "scaleType: fitEnd"/>
<ImageView
Android: id = "@ + id/image3"
Android: adjustViewBounds = "true"
Android: layout_width = "300dp"
Android: layout_height = "100dp"
Android: src = "@ drawable/macos01"
Android: scaleType = "fitEnd"
Android: background = "# F00"/>
<TextView
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "scaleType: fitCenter"/>
<ImageView
Android: id = "@ + id/image4"
Android: adjustViewBounds = "true"
Android: layout_width = "300dp"
Android: layout_height = "80dp"
Android: src = "@ drawable/macos04"
Android: scaleType = "fitCenter"
Android: background = "# F00"/>
</LinearLayout>
From sunset hut