Note
Please see the full version of this article for later updates:
Http://www.cnblogs.com/over140/archive/2011/06/08/2075054.html
Source: farmer Uncle: http://www.cnblogs.com/over140/
Body
First, the structure
Java.lang.Object
Android.view.View
Android.widget.ImageView
Known Direct subclasses:
ImageButton, Quickcontactbadge
Known indirect subclasses:
Zoombutton
Ii. Overview of the class
Displays any image, as an example. The ImageView class can load pictures from a variety of sources, such as a resource or a picture library, and needs to calculate the size of the image, which can be used in other layouts, and provides various display options such as zooming and shading (rendering).
Third, XML properties
|
Property name |
Describe |
|
Android:adjustviewbounds |
Whether to maintain the aspect ratio. Need to be used with maxwidth, maxheight, otherwise no effect is used alone. |
|
Android:croptopadding |
Whether to intercept the specified area with white space instead. Individually set no effect, need to work with scrolly, the effect is as follows, implementation code see Code section:
|
|
Android:maxheight |
Sets the maximum height of the view, which is not valid for use alone and needs to be used with setadjustviewbounds. If you want to set the image to a fixed size and want to maintain the picture aspect ratio, you need the following settings:
1) Set Setadjustviewbounds to true;
2) Set MaxWidth, MaxHeight;
3) Set settings Layout_width and Layout_height to Wrap_content. |
|
Android:maxwidth |
Sets the maximum width of the view. Ditto. |
|
Android:scaletype |
Sets how the picture is filled.
|
Matrix |
0 |
Use a matrix to draw |
|
|
Fitxy |
1 |
Stretch the picture (not proportionally) to fill the view's width height
|
Layout_
Height
: 30px
Layout_
Width
: 120px |
|
Fitstart |
2 |
Stretch the picture proportionally, the height of the picture is the height of the view, and it appears on the left side of the view
|
|
Fitcenter |
3 |
Stretches the picture proportionally to the height of the view and appears in the middle of the view
|
|
Fitend |
4 |
Stretch the picture proportionally, the height of the picture is the height of the view, and appears on the right side of the view
|
|
Center |
5 |
Displays the picture at the original size, but the picture is wider than the width of the view, and the middle part of the picture shows
|
Layout_
Height
: 60px
Layout_
Width
: 80px
Padding
: 10px
|
|
Centercrop |
6 |
Enlarges the original image proportionally to the width and height of a side view.
|
|
Centerinside |
7 |
When the original image is wide or equal to the width of the view, it is centered on the original size, whereas the original is scaled to the view's wide-height center display.
|
|
|
Android:src |
Set the view's drawable (slice, or color, but need to specify the size of the view) |
|
Android:tint |
Renders the picture as a specified color. See:
The left is the original, the right side is the set effect, see the following code. |
Four, the code
4.1 Android:tint
<ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@android: Color/white"android:src= "@drawable/btn_mode_switch_bg" ></ImageView><ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@android: Color/white"android:src= "@drawable/btn_mode_switch_bg"Android:tint= "#ffff00" ></ImageView>
4.2 android:croptopadding
<ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@android: Color/white"android:croptopadding= "true"android:scrolly= " -10px"android:src= "@drawable/btn_mode_switch_bg" ></ImageView><ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@android: Color/white"android:croptopadding= "true"android:scrolly= "10px"android:src= "@drawable/btn_mode_switch_bg" ></ImageView><ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@android: Color/white"android:croptopadding= "true"Android:paddingtop= "10px"android:scrolly= "10px"android:src= "@drawable/btn_mode_switch_bg" ></ImageView><ImageViewAndroid:layout_width= "Wrap_content"Android:layout_height= "Wrap_content"Android:background= "@android: Color/white"android:croptopadding= "false"Android:paddingtop= "10px"android:scrolly= "10px"android:src= "@drawable/btn_mode_switch_bg" ></ImageView>
Five, Series
Android2.2 API Chinese Document series (1)--textview
Android2.2 API Chinese Document series (2)--edittext
Android2.2 API Chinese Document series (3)--accessibilityservice
Android2.2 API Chinese Document series (4)--manifest
Android2.2 API Chinese Document series (5)--view
End
This article Android:tint property is interesting, and android:adjustviewbounds and android:croptopadding are difficult, it took more than one hours to try out the effect.
Android2.2 Api--imageview