2015-04-17 58 views
0

我有一個非常長的佈局來設計,我有它的設計和使用ScrollView,基本上它是1400dp長的佈局。我在我的活動中使用這個。我想在我的活動中實現一個固定頁腳,即使想要滾動要在頁面中固定的UI的頁面。添加一個固定頁腳到1400dp長佈局

這就是佈局代碼

<?xml version="1.0" encoding="utf-8"?> 
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#ffffff" 
    android:orientation="vertical" 
    android:paddingBottom="8dp" > 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="1400dp" 
     android:columnCount="1" 
     android:orientation="vertical" > 

     ... 
    </RelativeLayout> 

</ScrollView> 

我試圖頁腳(TextView的)添加至底部,然後它會隱藏滾動時。然後我試圖限制ScrollView,layout_height爲400dp,然後嘗試下面給出一個空白區域,但它不允許在那裏添加任何東西。 所以我的問題是,是否有可能在android佈局中添加修復頁腳。

enter image description here

+0

只需將您的ScrollView包裹在LinearLayout中,並將頁腳置於底部。 – 323go

回答

2

將scrollview包裝在RelativeLayout中。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/footer" 
     android:background="#ffffff" 
     android:orientation="vertical"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="1400dp" 
      android:columnCount="1" 
      android:orientation="vertical"> 
     ... 
     </RelativeLayout> 
    </ScrollView> 

    <YourFooter 
     android:id="@+id/footer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true"> 
    ...   
    </YourFooter> 
</RelativeLayout> 
+0

這個作品完美:) – modabeckham

0

步驟#1:包裹ScrollView在垂直LinearLayout,其高度和寬度都被設置爲match_parent

步驟#2:將ScrollView的高度設置爲0dip,並將權重設置爲1

步驟3:在LinearLayoutScrollView之後添加您的固定頁腳,將高度設置爲任何有意義的值(例如,wrap_content)。

現在,頁腳將在LinearLayout的底部給出其空間,剩下的空間將被分配給ScrollView

+0

我得到了我更新的問題(屏幕截圖)中顯示的錯誤,爲什麼? – modabeckham

+1

@modabeckham:在其他可能存在的問題中,您並沒有將LinearLayout垂直放置。你在'ScrollView'上放置了一個'android:orientation =「vertical」'屬性,而不是'LinearLayout'。也就是說,來自其他答案的'RelativeLayout'方法也適用。正如Perl人們所說的那樣,「有多種方式可以做到這一點」。 :-) – CommonsWare

+0

當然是的,謝謝你的詳細解答。每天我都在學習新事物。我非常感謝你的回答。歡呼聲 – modabeckham