2011-10-11 117 views
2

我有一個活動,在屏幕頂部有一個標題,在屏幕底部有一些按鈕元素,然後我想把中間(不管剩下的)用於滾動視圖。如何獲取Android視圖以佔用「剩餘」空間?

我知道如何去做所有事情,除了如何爲ScrollView分配一個高度來考慮上下的什麼,然後在兩者之間居住。

很想看到如何實現這種效果的XML示例。

TIA

+0

到目前爲止,您對XML佈局做了什麼? –

回答

8

您可以對此使用相對佈局。

<RelativeLayout android:layout_width="fill_parent" 
       android:layout_height="fill_parent"> 
    <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:id="@+id/header"> 
    <!--Header elements here--> 
    </LinearLayout> 
    <LinearLayout android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:alignParentBottom="true" 
       android:id="@+id/footer"> 
    <!--Footer element here--> 
    </LinearLayout> 
    <ScrollView android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_above="@+id/footer" 
       android:layout_below="@+id/header"> 
    </ScrollView> 
</RelativeLayout> 
+0

thx爲解決方案,它很好。你可以或其他人解釋爲什麼簡單地指定'scrollview'是'layout_below'' header'和'footer'是'layout_below'' scrollview'不應該達到相同的結果,當我的'footer'有50dp的'layout_height'?爲什麼android可能會解釋與解決方案不同的問題? – rockhammer

1

因此,在這種情況下,你想有頭(頂),滾動視圖(中)和按鈕(底部),這只是採取RelativeLayout的

3

如果你不想切換到RelativeLayout,我想你可以使用android:layout_weight屬性分配屏幕房地產。