2010-11-04 73 views
1

我想建立一個頂部的複選框,底部的按鈕和其他一些小部件之間滾動的一個活動。從概念上講這是
的LinearLayout
複選框
滾動型
的LinearLayout
[東東]
LinearLayout中高端
滾動型高端
按鈕
LinearLayout中高端
scrollview內linearlayout強制按鈕offscreen

當它呈現我得到的複選框在頂部,下面的東西很好地滾動,但在屏幕下方(我假設)繪製的按鈕滾動型。讓Button可見的唯一方法是對ScrollView的高度進行硬編碼,這當然只適用於一種屏幕尺寸。我試過重力和layout_weight的所有組合,我可以想到無濟於事。我是否使用Views的正確組合?有人設法得到這個工作?

(我不認爲RelativeLayout的是這個相當合適的容器,但無論我希望避免它,因爲它是在1.5打破。)

感謝,

--Eric

回答

0

我已經在2.2中使用了這個,不知道layout_above和layout_below標籤是否可用1.5(如果這是你使用的)。 佈置您要填充剩餘區域的三個主要元素,頁眉,頁腳和中心內容(在本例中爲列表視圖)。

如果需要,您可以用ListView替換ListView或任何組件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" android:layout_height="fill_parent"> 
    <Button 
     android:id="@+id/header" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Top Button"/> 
    <Button 
     android:id="@+id/footer" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:text="Button"/> 

    <ListView 
     android:id="@android:id/center" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_below="@id/header" 
     android:layout_above="@id/footer"/> 
    </RelativeLayout> 

請注意您的元素的順序。不確定它的相關性,但中心元素是最後定義的。

3

最近我有同樣的問題,我說:

<ScrollView 
    ... 
    android:layout_weight="1" > 

上解決了我的問題。