如何将三个布局设置为页眉,正文,页脚?

时间:2013-07-25 04:31:18

标签: android android-layout

如何将3布局设置为页眉,正文,页脚? (以下不起作用)。

<?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">

     <!-- HEADER -->
     <include android:id="@+id/top_header"
        layout="@layout/header2button"
        android:layout_alignParentTop="true" />

    <!-- BODY -->
    <LinearLayout android:id="@+id/center_body"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:orientation="vertical" 
        android:layout_alignParentBottom="true">
        <include layout="@layout/logo_2button" />
    </LinearLayout> 

    <!-- FOOTER -->
    <LinearLayout android:id="@+id/bottom_menu"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"         
        android:orientation="vertical" 
        android:layout_alignParentBottom="true">
        <include layout="@layout/footer2button" />
    </LinearLayout>


    <!-- MAIN PART -->
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_above="@id/top_header" 

        android:layout_below="@id/center_body"
        android:layout_below="@id/bottom_menu"
        android:layout_weight="1"
        android:id="@+id/sub_content_view"
        android:paddingBottom="5sp" android:background="#EAEAEA">
    </LinearLayout>

</RelativeLayout>

1 个答案:

答案 0 :(得分:3)

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:background="#654321"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Header"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Main Body"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#123456"
        android:gravity="center"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Footer"
            android:textAppearance="?android:attr/textAppearanceLarge" />

    </LinearLayout>

</LinearLayout>