2010-11-26 106 views
1

我想在背景圖像上顯示3個圖像。首先,我想到了使用相對佈局並將背景設置爲我的背景圖像。然後,我將這些圖像放置在佈局中:左側,中間和右側。問題是相對佈局填滿了整個屏幕,並且縮放了背景圖像。在佈局中使用背景圖像作爲圖像視圖不是一種選擇,因爲我希望我的3張圖像具有由背景高度確定的最大高度。達到此目的的最佳方法是什麼?這裏是我的代碼太:RelativeLayout wrap_content問題

問候

+0

所以,你想你的背景圖像的高度確定究竟是什麼HIGHT?我真的沒有得到它。 – 2010-11-26 19:15:33

+0

我想要背景圖像高度來確定佈局的高度。如果前景圖像的高度大於背景圖像高度,則應該自動縮小前景圖像的比例。 – Gratzi 2010-11-29 07:32:11

回答

2

首先,你的3個前景圖像線性排列,所以將它們放在一個水平LinearLayout。然後讓ImageView保存背景圖像,並將您的LinearLayout設置爲與ImageView的邊緣對齊。 ImageView的大小將由圖像內容決定。

即:

<RelativeLayout> 

    <ImageView android:id="@+id/background" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:src="@drawable/instruction_background" 
    /> 

    <LinearLayout 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:alignLeft="@id/background" 
    android:alignTop="@id/background" 
    android:alignRight="@id/background" 
    android:alignBottom="@id/background" 
    > 

    <ImageView ... /> 
    <ImageView ... /> 
    <ImageView ... /> 
    </LinearLayout> 
</RelativeLayout>