<ImageView
另外,android:background="@drawable/imageview_background"是給圖片加了一個邊框,其中
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屬性說明:
1、類概述
顯示任意圖像,例如圖標。ImageView類可以加載各種來源的圖片(如資源或圖片庫),需要計算圖像的尺寸,比便它可以在其他佈局中使用,並提供例如縮放和着色(渲染)各種顯示選項。
2、XML屬性
屬性名稱 |
描述 |
|||||||||||||||||||||||||||
android:adjustViewBounds |
是否保持寬高比。需要與maxWidth、MaxHeight一起使用,否則單獨使用沒有效果。 |
|||||||||||||||||||||||||||
android:cropToPadding |
是否截取指定區域用空白代替。單獨設置無效果,需要與scrollY一起使用,效果如下,實現代碼見代碼部分:
|
|||||||||||||||||||||||||||
android:maxHeight |
設置View的最大高度,單獨使用無效,需要與setAdjustViewBounds一起使用。如果想設置圖片固定大小,又想保持圖片寬高比,需要如下設置: 1) 設置setAdjustViewBounds爲true; 2) 設置maxWidth、MaxHeight; 3) 設置設置layout_width和layout_height爲wrap_content。 |
|||||||||||||||||||||||||||
android:maxWidth |
設置View的最大寬度。同上。 |
|||||||||||||||||||||||||||
android:scaleType |
設置圖片的填充方式。
|
|||||||||||||||||||||||||||
android:src |
設置View的drawable(如圖片,也可以是顏色,但是需要指定View的大小) |
|||||||||||||||||||||||||||
android:tint |
將圖片渲染成指定的顏色。見下圖: 左邊爲原圖,右邊爲設置後的效果,見後面代碼。 |