Previous: http://www.bkjia.com/kf/201208/148369.html
ImageView can display an image, which supports reading images (such as resource files or Content providers) from multiple data sources and managing the image size to adapt to different Layout managers, allows you to scale and arrange images.
In this example, the layout file and ImageView attributes are used to set the ImageView attributes:
Non-scaled view No zoom display
<ImageView
Android: src = "@ drawable/sample_1 ″
Android: adjustViewBounds = "true"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
When adjustViewBounds is true, the ImageView is adjusted to adjust its boundary rectangle to maintain the aspect ratio of the image (the image is not deformed.
Limit to at most 50X50 Limit maximum image size 50X50
<ImageView
Android: src = "@ drawable/sample_1 ″
Android: adjustViewBounds = "true"
Android: maxWidth = "50dip"
Android: maxHeight = "50dip"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
Limit to at most 70 × 70, with 10 pixels of padding Limit the maximum image size is 70X70 (including 10 pixel padding)
<ImageView
Android: src = "@ drawable/sample_1 ″
Android: background = "# 66FFFFFF"
Android: adjustViewBounds = "true"
Android: maxWidth = "70dip"
Android: maxHeight = "70dip"
Android: padding = "10dip"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"/>
Limit to exactly 70 × 70, with 10 pixels of padding set the image size to exactly 70 × 70 (including 10 pixel Padding)
<ImageView
Android: src = "@ drawable/sample_1 ″
Android: background = "# 66FFFFFF"
Android: scaleType = "centerInside"
Android: padding = "10dip"
Android: layout_width = "70dip"
Android: layout_height = "70dip"/>
Android: scaleType defines how to scale an image to fit the View area. You can:
CENTER: No scaling. Place the Image in the CENTER of the View.
CENTER_CROP: proportional scaling of the image. The width or length of the scaled image is equal to or greater than the width and length of the View.
CENTER_INSIDE: proportional scaling of the image. The width or length of the scaled image is equal to or less than the width and length of the View.
FIT_CENTER: scale the image in Matrix. ScaleToFit. CENTER mode.
FIT_END: scales the image in Matrix. ScaleToFit. END mode.
FIT_CENTER: scale the image in Matrix. ScaleToFit. CENTER mode.
FIT_START: Use the Matrix. ScaleToFit. START mode to scale the image.
FIT_XY: scales the image in Matrix. ScaleToFit. XY mode.
FIT_MATRIX: Use the Matrix of the Image to scale the Image.
The following examples use a very small image with the same display property as above:
Author: mapdigit