2010-09-24 67 views
21

我用Layout_width="fill_parent「和Layout_height="wrap content"。如果圖像比ImageView的更大,這將是完全按比例縮小。是否android:scaleType =「fitCenter」僅適用於修補Layout_width和Layout_height屬性?

但是,我從來沒有得到它的工作,以高檔的小圖像。我試圖和ScaleType任意組合‘AdjustViewBounds’ :它總是停留在圖像取景當中自己的大小這裏是代碼...

<LinearLayout 
     android:id="@+id/LinearLayout02" 
     android:layout_height="wrap_content" 
     android:background="@drawable/content_bg" 
     android:orientation="vertical" 
     android:padding="5dp" 
     android:layout_width="fill_parent" 
     android:layout_marginLeft="1px"> 
     <ImageView 
      android:layout_height="wrap_content" 
      android:src="@drawable/test" 
      android:id="@+id/ImageViewTest" 
      android:layout_width="fill_parent" 
      android:adjustViewBounds="true" 
      android:scaleType="center"></ImageView> 
</LinearLayout> 
+0

嘗試使用CENTER_INSIDE或FIT_XY。 – bhups 2010-09-24 09:02:05

+0

我嘗試了所有這些。他們都沒有爲我工作。 – OneWorld 2010-09-24 09:12:48

+4

我發現讓它工作的唯一方法是將layout_hight和layout_width設置爲固定值,如150dp x 200dp – OneWorld 2010-11-05 21:39:03

回答

1

添加android:scaleType="fitXY"到烏爾的ImageView應該拉伸圖像,如果尺寸小

+3

那麼,不保持高寬比... – OneWorld 2010-11-05 21:35:29

+0

是的,如果圖像較大,但它的尺寸較小,則只適合高度或寬度。愚蠢的Android處理圖像的方式 – JPM 2015-03-25 20:55:06

4
<LinearLayout 
    android:layout_height="wrap_content" 
。 210

使用裏面的圖像的原始大小。

嘗試更大的東西或FILL_PARENT

+0

這只是我的一個黃金答案,你不知道我有多少麻煩,我已經與imageview及其錯誤(或誤解)scaletype。 Thamls一噸。 – Warpzit 2011-12-04 21:06:35

2

使用android:scaleType="FIT_START"android:scaleType="FIT_END",來計算規模,將保持原來的SRC寬高比,但也將確保SRC完全符合內部DST(從GoogleDev)。

更多信息:

http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

+2

它是android:scaleType =「fitStart」或android:scaleType =「fitEnd」,它們幾乎與android:scaleType =「fitCenter」完全相同。不同之處在於他們如何處理空白空間,如何開始,結束或居中。 – OldSchool4664 2012-12-12 01:01:27

9

我只是找到了一種方法,使其工作。

這適用於2.1(AVD)& 4.1.2(裝置)

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:scaleType="fitCenter" /> 

</LinearLayout> 
+1

用這種方法,如果你在imageView上有一個邊框,在圖像沒有縮放到的邊上會有空白 – Olumide 2014-06-25 23:12:18

相關問題