Android-ui component Instance Daquan (vi)------ImageView Image View

Source: Internet
Author: User

Image view: ImageView

Inherits the view class, which is used to display any drawable object on the screen and is typically used to display pictures:

Here we introduce some of the more commonly used properties:

Path 1:

Android:adjustviewbounds: Sets whether ImageView adjusts its boundaries to maintain the aspect ratio of the displayed picture

!!! The following two properties need to adjustviewbounds for ture, otherwise it will not work Oh!

Android:maxheight: Setting the maximum height of the ImageView

Android:maxwidth: Sets the maximum width of the ImageView

Instance:

Code:

<!--normal Pictures--    <imageview        android:src= "@drawable/meinv9"        android:id= "@+id/imageview1"        Android:layout_margin= "5px"        android:layout_height= "wrap_content"        android:layout_width= "Wrap_content"     /><!--limits the maximum width and height, and sets the adjustment boundary to maintain the aspect ratio of the displayed image-    <imageview        android:src= "@drawable/meinv9"        android:id= "@+id/imageview2"        android:maxwidth= "200px"        android:maxheight= "200px"        android: Adjustviewbounds= "true"        android:layout_margin= "5px"        android:layout_height= "Wrap_content"        Android:layout_width= "Wrap_content"     />


Run:

Code Explanation:

The big picture is nothing to deal with the picture, the following one words we pass maxwidth and maxheight limit imageview maximum width and height of 200px

is to show only 200*200 pictures, we set a adjustviewbounds = "true" to adjust our boundaries to maintain the aspect ratio of the picture, at this time the ImageView is 87*133

Path 2:

Android:scaletype: Sets how the displayed picture is scaled or moved to fit the ImageView size

Property:

Fitxy: Independent scaling of the image's landscape and portrait, making the picture fully adaptable to the ImageView, but the picture's aspect ratio may change

Fitstart: Maintain aspect ratio zoom picture, know long edge is equal to image programming, put picture in upper left corner of ImageView when Zoom is finished

Fitcenter: Ibid., after zooming in the middle;

Fitend: Ibid., after zooming in the lower right corner;

Center: Do not do any processing directly to the picture in the ImageView center

Centercrop: Keep the horizontal ratio zoom picture, know completely overwrite ImageView, may appear the picture is not displayed completely

Centerinside: Keep the horizontal aspect ratio to scale the picture until ImageView can display the picture completely

Matrix: Using matrix mode to zoom, this is a bit complicated, not to introduce ...

Instance:

1.fitend,fitstart,fitcenter use, here with Fitend as a demonstration

Code:

<!--keep The picture's aspect ratio scaled, know that the picture can be displayed on the ImageView component, and display the scaled picture in the lower-right corner of the ImageView-    <imageview        android:src= "@ Drawable/meinv9 "        android:id=" @+id/imageview3 "        android:layout_margin=" 5px "        android:layout_width=" 180px "        android:layout_height=" 180px "        android:scaletype=" Fitend "     />

Run:


Code explanation: Keep the aspect ratio scaled until the longest edge is equal to the imageview edge, Zoom complete, and place the picture in the lower right corner

The rest of the two similar

2.centerGroup and Centerinside

Code:

<imageview        android:src= "@drawable/meinv9"        android:id= "@+id/imageview3" android:layout_margin= "        5px "        android:layout_width=" 180px "        android:layout_height=" 180px "        android:scaletype=" Centercrop "     />    <imageview        android:src= "@drawable/meinv9"        android:id= "@+id/imageview3"        android: Layout_margin= "5px"        android:layout_width= "180px"        android:layout_height= "180px"        android: Scaletype= "Centerinside"     />


Run:

Code Explanation: Centercrop: Scale by the horizontal ratio, directly cover the entire ImageView

Centerinside: Scale by aspect ratio, so that imageview can display this picture completely

Path 3:

Android:tint: Coloring a picture, fill in a color value

Code:

<imageview        android:src= "@drawable/meinv9"        android:id= "@+id/imageview3" android:layout_margin= "        5px "        android:layout_width=" 180px "        android:layout_height=" 180px "        android:scaletype=" Centerinside "        android:tint= "#77ff0000"     />

Run:

Code explanation: And the above is almost, just a tint: ..., coloring the picture

http://www.fenby.com/blog/blog/300

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.