Android ApiDemos樣本解析(125):Views->ImageView

來源:互聯網
上載者:User

上一篇:http://www.bkjia.com/kf/201208/148369.html


ImageView 可以顯示一個映像,比標,它支援從多種資料來源讀取映像(比如資源檔或是Content Provider),並支援對映像大小管理以適應不同的Layout Manager,並允許縮放圖形,柏拉圖像等。

本例使用layout 檔案,使用ImageView的屬性來設定ImageView的屬性:

Non-scaled view 無縮放顯示

<ImageView
android:src=”@drawable/sample_1″
android:adjustViewBounds=”true”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

adjustViewBounds 為true時表示調整ImageView調整其邊界矩形以保持映像的縱橫比(映像不變形。

 

Limit to at most 50×50 限制映像最大為50X50

<ImageView
android:src=”@drawable/sample_1″
android:adjustViewBounds=”true”
android:maxWidth=”50dip”
android:maxHeight=”50dip”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

 

Limit to at most 70×70, with 10 pixels of padding 限制映像最大為70X70(含10像素padding)

<ImageView
android:src=”@drawable/sample_1″
android:background=”#66FFFFFF”
android:adjustViewBounds=”true”
android:maxWidth=”70dip”
android:maxHeight=”70dip”
android:padding=”10dip”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content” />

 

Limit to exactly 70×70, with 10 pixels of padding 將映像大小設為正好70×70(含10像素Padding)

<ImageView
android:src=”@drawable/sample_1″
android:background=”#66FFFFFF”
android:scaleType=”centerInside”
android:padding=”10dip”
android:layout_width=”70dip”
android:layout_height=”70dip” />

android:scaleType 定義了如何縮放映像以適應View的地區,可以有:

CENTER: 無縮放,將Image放在View的中心。
CENTER_CROP: 等比例縮放映像,縮放後映像的寬度或是長度等於或是大於View的寬度和長度。
CENTER_INSIDE: 等比例縮放映像,縮放後映像的寬度或是長度等於或是小於View的寬度和長度。
FIT_CENTER: 使用Matrix.ScaleToFit.CENTER 模式縮放映像。
FIT_END: 使用Matrix.ScaleToFit.END 模式縮放映像。
FIT_CENTER: 使用Matrix.ScaleToFit.CENTER 模式縮放映像。
FIT_START: 使用Matrix.ScaleToFit.START 模式縮放映像。
FIT_XY: 使用Matrix.ScaleToFit.XY 模式縮放映像。
FIT_MATRIX: 使用Image的Matrix縮放映像。

後面的幾個例子使用一個很小的映像使用和上面同樣的顯示內容:

 
作者:mapdigit
 

 
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.