2012-12-18 107 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.

希望这一切帮助你。如果没有,那么让我知道。

享受编码。 :)

相关问题