2012-01-23 87 views
1

屏幕上有一個頁眉和頁腳,屏幕中心(Content Area)被ScrollView佔據。當我啓動應用程序時,會顯示頁腳。但是,當我點擊元素「A」時,它會在屏幕上顯示更多元素,並推動下面的其他元素。 ScrollView確實使中心部分可滾動,但它也隱藏了頁腳(屏幕底部的灰色LinearLayout)。如何防止ScrollView隱藏頁腳?

如何讓頁腳保留在屏幕底部?我只想要內容區域滾動。頁眉和頁腳XML位於ScrollView元素之外。我嘗試使用RelativeLayout代替LinearLayout,但沒有任何成功。

以下是點擊元素「A」之前和之後的外觀。

Before click

After click

我可以提供的代碼,XML和Java,如果需要的話,但它是非常的代碼。

+0

請把你的整個XML,所以我們可以瞭解如何保持整個佈局。我們可以幫助你更正確的方式。 –

回答

8
<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" > 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="1" 
     android:fillViewport="true"> 

     <LinearLayout 
      android:id="@+id/linearLayout1" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" > 
     </LinearLayout> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/linearLayout2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content"> 

     <Button 
      android:id="@+id/button1" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Button" /> 

    </LinearLayout> 

</LinearLayout> 

使用重量的高度佈局

+0

我也這麼認爲。此代碼將起作用。 – lulumeya

+0

'android:layout_weight =「1」'用於使'match_parent/fill_parent'頂部的視圖位於'wrap_content'高度下面的視圖。謝謝! –

0

Scrollviews直接子對高級內容不能有高度屬性。我認爲你宣佈包裝不是嗎?該意見高度必須有不可調整大小

1
<?xml version="1.0" encoding="utf-8"?> 
<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:layout_alignParentTop="true" 
    android:text="Header view" /> 

<ScrollView 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:id="@+id/content" 
    android:layout_below="@id/header" > 

    <LinearLayout 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:orientation="vertical" > 

    ////////////// 



    </LinearLayout> 
</ScrollView> 

<Button 
    android:id="@+id/footer" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:text="Footer View" /> 

+0

這樣,scrollview的最下部分就隱藏在頁腳後面。 – sandalone