Android ApiDemos example resolution (125): Views-& gt; ImageView

Source: Internet
Author: User

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
 

 
 

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.