如何在android中创建带有页眉和页脚窗格布局的2个左右窗格?

时间:2014-11-25 12:55:11

标签: android android-layout

就像这样

< - 头 - >

左|右

< - 页脚 - >

我将在标题窗格中放置搜索textBox,然后在左窗格中放置listView,右窗格将显示文本字段以显示listView中所选项目的详细信息。页脚上会有一些Buttons

3 个答案:

答案 0 :(得分:1)

我通常不是“问及获取”方法的粉丝。您必须显示到目前为止您尝试过的内容,并解释您的代码无法解决的问题。但是,既然你没有就你的问题提供更多的反馈,那么就这样吧。您可以使用LinearLayoutsRelativeLayouts作为父Views这样的简单布局。然后,在这些父视图中插入您引用的特定ViewsTextViewListView)。像这样:

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

    <LinearLayout
        android:id="@+id/headerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:orientation="vertical" >


    </LinearLayout>

    <LinearLayout
        android:id="@+id/contentLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/headerLayout"
        android:gravity="center"
        android:orientation="horizontal"
        android:weightSum="2" >

        <ListView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1" >
        </ListView>

        <TextView
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:gravity="center"
            android:text="Description" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/footerLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:orientation="horizontal" >

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button1" />
    </LinearLayout>

 </RelativeLayout>

这只是一个划痕。但是从这里开始,您可以按照自己喜欢的方式进行成本计算。

答案 1 :(得分:1)

<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="com.example.layouttest.MainActivity" >

<EditText
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="@android:color/white"
    android:text="I am Header" />

<Button
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:text="I am Footer" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="200dp"
    android:layout_centerVertical="true"
    android:weightSum="2" >

    <ListView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:divider="@android:color/black"
        android:dividerHeight="2px"
        android:padding="5dp" >
    </ListView>

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:gravity="center"
        android:hint="Details of List View" />
</LinearLayout>

 </RelativeLayout>

答案 2 :(得分:0)

This Example  可以帮助您处理RelativeLayout中的页眉和页脚。