2013-05-29 51 views
0

我有4個ImageView/ImageButtons的Linearlayout。所有圖像具有相同的寬度和高度。我想此佈局總是配合父母的寬度和所有圖像用相同的縱橫比(寬度和高度)規模:在具有相同寬度和高度比的不同屏幕尺寸下調整ImageView/ImageButton的大小

enter image description here

我嘗試這樣做:

<LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

    <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:src="@drawable/item_background" 
      android:layout_weight="1" 
      android:adjustViewBounds="true"/> 
    // All 4 images are the same 
</LinearLayout> 

的問題是,之間的比例在土地/肖像的寬度和高度是不一樣的。例如,在橫向模式下,圖像被拉伸僅在x軸而不是Y軸:

enter image description here

我不想在代碼中去,例如僅UI的東西,我希望你能幫助我找到一種在XML中做到這一點的方法!

編輯:

添加機器人之後:scaleType = 「fitXY」 將圖像我得到這個:

enter image description here

,正如你所看到的是不是一個很好的解決了我想要的東西。

回答

0

可以使用

android:scaleType="fitXY" 

它會適應的資源在你的ImageView。

+0

我編輯了Q,你可以看到這不是我想要的。 –

0

使用android:layout_width="match_parent"android:scaleType="FIT_CENTER"

0

這可能是正常的,因爲你的LinearLayout的方向是「橫向」。

解決你的問題,你可以使用以上驗證碼回答。

+0

我將所有圖像的layout_weight設置爲1.所以這不是問題。 –

+0

我認爲你的代碼在橫向模式下很好,我試過了,沒問題。 android:adjustViewBounds =「true」保留圖像的寬高比 – codebringer

0

有一個.9.png圖像格式,爲Android開發的,它可以幫助你解決這個問題,這裏是來自Android開發者網站上的鏈接Draw9patch

相關問題