2011-04-04 111 views
0

在Android中,我試圖使用xml來獲得類似this image的佈局。如何在android中設置此佈局?

enter image description here

我一直試圖做的是垂直分成兩個部分視圖分離。一個用於藍色部分,另一個用於白色。對於藍色部分,我使用一個形狀作爲背景來獲得漸變,白色部分只是一個白色背景。它適用於「標題」和「某些文本」部分。但是,由於圖像視圖應該覆蓋兩個佈局,因此不起作用。

我無法弄清楚如何設置xml佈局以使其工作,任何想法?

回答

1

我會做這樣的:

<RelativeLayout> 
    <TextView 
     android:id="@+id/title" 
     android:layout_alignParentTop="true" 
     android:text="title" 
     /> 
    <TextView 
     android:layout_below="@id/title" 
     android:layout_alignParentBottom="true" 
     android:text="some text here" 
     /> 
    <ImageView 
     android:layout_alignParentLeft="true" 
     android:text="title" 
     /> 
</RelativeLayout> 

當然,你需要設置佈局寬度,高度。 ..在這些元素上。

+0

太棒了!當爲兩個TextView設置layout_width =「fill_parent」和layout_height =「wrap_content」時,這種工作非常完美。現在唯一的問題是ImageView和圖像裏面的圖像位於左上角,我希望它垂直居中,這怎麼可能? – Martin 2011-04-04 16:29:43

+0

檢查RelativeLayout文檔,你會發現你需要的所有屬性。特別是,其中一個被命名爲layout_centerVertical – 2011-04-05 08:24:27

+0

謝謝我發現了我正在尋找的東西! – Martin 2011-04-05 09:18:58