標籤:
Android ImageView圖片自適應 (2011-12-07 11:28:25)
轉載▼
| 標籤:androidimageview圖片自適應加外框雜談 |
分類: android |
網路上下載下來的圖片自適應:android:adjustViewBounds="true"(其詳細解釋在下面)
<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"/>
另外,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 |
設定圖片的填充方式。
matrix |
0 |
用矩陣來繪圖 |
|
fitXY |
1 |
展開圖片(不按比例)以填充View的寬高 |
layout_ height :30px layout_
width :120px |
fitStart |
2 |
按比例展開圖片,展開後圖片的高度為View的高度,且顯示在View的左邊 |
fitCenter |
3 |
按比例展開圖片,展開後圖片的高度為View的高度,且顯示在View的中間 |
fitEnd |
4 |
按比例展開圖片,展開後圖片的高度為View的高度,且顯示在View的右邊 |
center |
5 |
按原圖大小顯示圖片,但圖片寬高大於View的寬高時,圖片中間部分顯示
|
layout_ height :60px layout_
width :80px padding
:10px |
centerCrop |
6 |
按比例放大原圖直至等於某邊View的寬高顯示。 |
centerInside |
7 |
當原圖寬高或等於View的寬高時,按原圖大小置中顯示;反之將原圖縮放至View的寬高居 |
|
Android ImageView圖片自適應