2011-06-01 56 views
1

我有一個ImageView,它顯示來自資源的圖像。 ImageView的widht是固定的(60dp)。高度設置爲wrap_content。 圖像被調整大小以適應這個寬度(節省寬高比 - 這是完美的)實際視圖的高度不適合正確的內容

問題是,android在調整大小之前將實際高度設置爲圖像的高度。但是我希望這幅圖像的寬度恰好爲60dp,並且在調整大小後高度應該等於圖像的高度。

這是解決的辦法很簡單,我只是增加屬性附加傷害android:adjustViewBounds="true"ImageView標籤佈局

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:layout_width="60dp" 
     android:layout_height="wrap_content" 
     android:src="@drawable/sample" 
     android:background="#F0F0"/> 
</LinearLayout> 

enter image description here

回答

1

嘗試安卓adjustViewBounds = 「真」

0

有兩個解決方案

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <ImageView 
     android:layout_width="60dip" 
     android:layout_height="wrap_content" 

     android:background="@drawable/thumb" 
     android:adjustViewBounds="true"/> 
</LinearLayout>