问题描述
- 设置三个布局作为header,body,footer
-
如题如何设置三个布局作为标题,文本和页脚?我用了下面的代码没实现。<?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>
解决方案
<?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>
时间: 2025-01-19 07:52:02