2011-10-26 59 views
0

我有2個LinearLayouts和一個相對佈局中的按鈕。 他們應該是這樣的:如何設置具有頂部,中間和底部元素的佈局?

一個的LinearLayout與頂欄(約畫面的20%。)


大量的滾動視圖,其佔據了大部分屏幕(約元素的60。屏幕%)


我試圖此底部(約屏幕的20%)甲按鈕:

<RelativeLayout 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <LinearLayout 
    android:id="@+id/layoutTopBlack" 
    android:layout_alignParentTop="true" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"> 
    <include layout="@layout/top_black_bar_cancel_register_button"/> 
</LinearLayout> 

    <LinearLayout 
    android:id="@+id/layoutCenter" 
    android:layout_below="@id/layoutTopBlack" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 
    <include layout="@layout/top_black_bar_cancel_register_button"/> 
</LinearLayout> 

    <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:id="@+id/buttonNextStep" 
    android:text="@string/next_step" 
    style="@style/mainButtonStyle"/> 

</RelativeLayout> 

這不起作用。 layoutCenter放在按鈕上,所以我從來沒有看到按鈕。

有什麼建議嗎?

在此先感謝。

編輯: 我發現這個從編輯: 無法解析資源@ ID/layoutTopBlack

回答

0

只要告訴你的layoutCenter佈局本身上面的按鈕,這樣的事情:

<LinearLayout 
android:id="@+id/layoutCenter" 
android:layout_above="@id/buttonNextStep" 
android:layout_below="@id/layoutTopBlack" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent"> 
<include layout="@layout/top_black_bar_cancel_register_button"/> 
</LinearLayout> 
+0

嗯,我得到無法解決資源@ id/layoutTopBlack,即使我已經添加了@ + ID/ – Ikky

+0

@Ikky你是如何解決你的問題與無法解決資源?我通常只是使用@ + id /移動資源,直到它工作。 –

0

其實,考慮到你提到的百分比,你可能想在這裏使用LinearLayoutlayout weights,而不是RelativeLayout。

EG做你提到的20%/ 60%/ 20%重量:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <View android:layout_height="0px" android:layout_weight="1" ... /> 
    <View android:layout_height="0px" android:layout_weight="3" ... /> 
    <View android:layout_height="0px" android:layout_weight="1" ... /> 
</LinearLayout> 

如果頂部/底部的酒吧只需要吸引他們的內容,不會佔用固定的百分比,然後耶南。 antune的答案應該可以工作,或者你可以使用類似於上面的LinearLayout,但是設置頂部/底部的小節來包裝內容而不用設置權重。然後,中央視圖上的任何重量都將使其填充所有可用剩餘空間,而不會像fill_parent那樣清除按鈕。

相關問題