2012-12-18 200 views

回答

7

更簡單的方法是使用:

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

    <LinearLayout 
     android:id="@+id/headerView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true" > 
    </LinearLayout> 

    <ScrollView 
     android:id="@+id/scrollablContent" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@+id/footerView" 
     android:layout_below="@+id/headerView" > 

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

    <LinearLayout 
     android:id="@+id/footerView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" > 
    </LinearLayout> 

</RelativeLayout> 
+1

它不工作 – DroidLearner

+0

它只是一個示例,您必須將您的小部件添加到特定的組視圖,例如您的頭部必須添加到LinearLayout headerView。 –

+0

好吧!!!!!!!!! – DroidLearner

2

你必須從LinearLayout中更換外部容器的RelativeLayout,然後設置的alignParentTop =真對於ScrollView,頁眉ImageView,alignParentBottom = true爲頁腳ImageView,並設置layout_above =「@ + id/imageViewFooter」,layout_below =「@ + id/imageViewHeader」。像這樣:

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

    <ImageView 
     android:id="@+id/imageViewHeader" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentRight="false" 
     android:layout_alignParentTop="false" 
     android:scaleType="fitXY" 
     android:src="@drawable/square" /> 

    <ImageView 
     android:id="@+id/imageViewFooter" 
     android:layout_width="match_parent" 
     android:layout_height="60dp" 
     android:layout_alignParentBottom="true" 

     android:scaleType="fitXY" 
     android:src="@drawable/square" /> 

    <ScrollView 
     android:id="@+id/scrollView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_above="@+id/imageViewFooter" 

     android:layout_below="@+id/imageViewHeader" > 

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

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

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

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

      <Button 
       android:id="@+id/button4" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Button" /> 
     </LinearLayout> 
    </ScrollView> 

</RelativeLayout> 
+0

如何設置這個'android:scaleType =「fitXY」'和'android:src =「@ drawable/square」' – DroidLearner

+0

MyBAD !!我知道了.. fitXY – DroidLearner

+0

是什麼意思fitXY只是告訴ImageView圖像必須符合強加的尺寸,而不考慮比例。 – moondroid

3

你可能想要帶有頁眉和頁腳的listView。

你見過this?

請參見this one.

this one.

希望這一切幫助你。如果沒有,那麼讓我知道。

享受編碼。 :)

相關問題