2012-08-07 201 views
8

我看了很多關於Stackoverflow的問題,並嘗試了很多解決方法,但仍然無法使用。調整圖像大小以適合Imageview

我想實現什麼:

enter image description here enter image description here

但我實現這一目標:

enter image description here

這是我目前的XML代碼:

<ImageView 
    android:id="@+id/image" 
    android:layout_width="fill_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/text" 
    android:layout_gravity="center" 
    android:adjustViewBounds="true" 
    android:scaleType="centerInside" 
    android:src="@drawable/ic_action_search" /> 

回答

1

CenterInside,根據視圖尺寸及其分辨率調整圖像大小。因此,如果圖像的大小爲300 * 450,並且我們將此圖像設置爲縮放類型centerinside的圖像視圖,並且尺寸爲200 * 400,那麼它將使圖像尺寸爲200 * 300。根據目標尺寸,它下來使200是最小的寬度和高度。我希望我很清楚。如果您需要設置精確尺寸的尺寸,請按照Adeel的建議使用FItXY。

3

實現此目的的最佳方法是使用矩陣縮放圖像(位圖)。

另一種方法是使用之前創建它爲您完成此庫:

https://github.com/laurencedawson/ZoomableImageView

這將自動縮放圖片以適應屏幕並添加捏縮放。

+0

如何去使用它嗎?是否有任何教程或示例代碼?因爲我正在使用它在lazyload類的listview中加載圖像。謝謝! – MrYanDao 2012-08-07 11:55:00

+0

對不起沒有意識到你使用的是一個listview,可能不是最好的選擇(由於垂直滾動)。 如果您看一下繪圖和縮放代碼,它應該可以幫助您。 – Ljdawson 2012-08-07 12:09:38

+0

好吧,會好的!非常感謝^^ – MrYanDao 2012-08-07 12:11:34

2

添加

<ImageView 
android:id="@+id/image" 
android:layout_width="fill_parent" 
android:layout_height="match_parent" 
android:layout_below="@+id/text" 
android:layout_gravity="center" 
android:adjustViewBounds="true" 
android:scaleType="fitXY" 
android:src="@drawable/ic_action_search" /> 
0

你想這樣做的XML文件裏面的權利?

<ImageView 
android:layout_width="size of image (in density pixels)" 
android:layout_height="size of image (in density pixels)" /> 

因此,例如:

<ImageView 
android:layout_width="60dp" 
android:layout_height="60dp" /> 
相關問題