Images downloaded on the web are self-adapting:android:adjustviewbounds= "true" (which is explained in detail below)
<imageview android:id= "@+id/dynamic_item_image"android:layout_width= "Wrap_content"android:layout_height= "Wrap_content"android:layout_gravity= "Top"android:layout_margintop= "5dip" android:adjustviewbounds= "true"
android:background= "@drawable/imageview_background"/>
Additionally, Android: background= "@drawable/imageview_background" is to add a border to the picture, where
Imageview_background.xml:
<?xmlversion= "1.0" encoding= "Utf-8"? ><shape xmlns:android= "http://schemas.android.com/apk/res/android" ><solid android:color= "@color/white"/>< Stroke android:width= "2.0dip" android:color= "#99D9D9D9"/> <cornersandroid:radius= "2.0dip"/> < paddingandroid:left= "5.0dip" android:top= "5.0dip" android:right= "5.0dip" android:bottom= "5.0dip"/></shape
ImageView Property Description:
1. Class overview
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).
2. Xml attributes
|
|
description |
| android:adjustviewbounds
|
whether to maintain the aspect ratio. Need to be used with Maxwidth, Maxheight use, 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
|
draw with matrix |
&NBSP;
|
|
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 View left
&NBSP; |
| fitcenter
|
3
|
stretch the picture proportionally, the height of the picture is View Middle
&NBSP; |
| fitend
|
4
|
stretch the picture proportionally, the height of the picture is View
&NBSP; |
|
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
&NBSP; |
| centercrop
|
6
|
zoom in on the original until it equals one side View&NBSP; |
| centerinside
|
7
|
When the original width is high or equal to View
&NBSP; |
|
| android:src
|
set view Drawable (", or color, but you need to specify 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. |
Android ImageView Picture Adaptive