Android 与锚定顶部和底部的相对长度?

Android 与锚定顶部和底部的相对长度?,android,android-layout,Android,Android Layout,我正在尝试创建一个android屏幕,它有一个固定在顶部的TableLayout,然后是一个填充中间的scrollview,以及一个固定在底部的TableLayout。我使用了带有alignParentTop/alignParentBottom的RelativeLayout,显示了底部的表格布局,但顶部的表格布局消失了 是否有可能在顶部和底部锚定单独的部分,中间填充一个可滚动区域?想象一下,顶部和底部有一个按钮条,中间有可滚动的物品。这是我的布局,虽然很接近,但不太有效。我还尝试使用一个Tabl

我正在尝试创建一个android屏幕,它有一个固定在顶部的TableLayout,然后是一个填充中间的scrollview,以及一个固定在底部的TableLayout。我使用了带有alignParentTop/alignParentBottom的RelativeLayout,显示了底部的表格布局,但顶部的表格布局消失了

是否有可能在顶部和底部锚定单独的部分,中间填充一个可滚动区域?想象一下,顶部和底部有一个按钮条,中间有可滚动的物品。这是我的布局,虽然很接近,但不太有效。我还尝试使用一个TableLayout和3行,中间一行设置为填充父视图和ScrollView,但也无法实现

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinearLayout01"
  android:orientation="vertical"
  android:layout_width="match_parent"
  android:layout_height="match_parent">
  <TableLayout
       android:id="@+id/CategoryTable01"
        android:stretchColumns="*"
        android:background="#000000"
        android:layout_height="80px"
        android:layout_alignParentTop="true"
        android:layout_width="fill_parent">
        <TableRow 
            android:id="@+id/tr01"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:padding="10px"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:text="TOP1" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="TOP2" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
        </TableRow>
   </TableLayout>
<ScrollView android:id="@+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinearLayout02"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">
    <TableLayout
        android:id="@+id/TableLayout01"
        android:stretchColumns="*"
        android:background="@drawable/gradient"
        android:layout_height="wrap_content"
        android:paddingLeft="20px"
        android:layout_width="fill_parent">
        <TableRow
            android:id="@+id/TableRow01"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:textColor="#FFFFFF"
                android:textStyle="bold"
                android:textSize="12dip"
                android:text="Sample Line 1"></TextView>
        </TableRow>
        <TableRow
            android:id="@+id/TableRow02"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:textColor="#FFFFFF"
                android:textSize="11dip"
                android:text="Sample Line 2"></TextView>
        </TableRow>
        <TableRow
            android:id="@+id/TableRow03"
            android:layout_height="600px"
            android:layout_width="wrap_content"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:textColor="#FFFF00"
                android:textSize="11dip"
                android:text="Sample Line 3"></TextView>
        </TableRow>
    </TableLayout>
    </LinearLayout>
    </ScrollView>
  <TableLayout
       android:id="@+id/CategoryTable02"
        android:stretchColumns="*"
        android:background="#000000"
        android:layout_height="80px"
        android:layout_alignParentBottom="true"
        android:layout_width="fill_parent">
        <TableRow 
            android:id="@+id/tr02"
            android:layout_height="fill_parent"
            android:layout_width="wrap_content"
            android:padding="10px"
            android:layout_gravity="center_vertical|center_horizontal">
            <TextView android:text="ONE" android:textColor="#0000FF" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="TWO" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="THREE" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
            <TextView android:text="FOUR" android:textColor="#CCCCCC" android:layout_height="fill_parent" android:layout_gravity="fill_vertical" android:textStyle="bold" />
        </TableRow>
   </TableLayout>
</RelativeLayout>

谢谢你的建议和帮助


迈克尔

这确实是可能的。这就是我如何让它在我的一个应用程序中工作(我删掉了一堆不相关的东西,比如ID):



关键是将中间的listview设置为height 0dip,并让layout_weight接管-layout_weight有点类似于HTML中的宽度/高度百分比-如果您有4个不同的元素,其权重为0.25,则每个元素将占据屏幕的四分之一。因此,重量1.0会占据一切空间。

非常酷,非常感谢!布局重量的解释非常有用,我想我是想让布局高度=“填充家长”扮演这个角色。我切换到TableLayout是因为我的项目不喜欢片段,我想是因为目标api级别。我还没有真正使用过片段,它看起来像是API级别11中引入的东西?我对android的开发还是有点陌生,所以我还不确定应该使用哪些元素。例如,我有ScrollView->LinearLayout->TableLayout这样我就可以滚动了,但如果ListView也这样做的话,那就太过分了
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <!--this is the action bar at the top of the screen)-->
    <fragment
            android:layout_width="match_parent"
            android:layout_height="40dip" />

    <!-- This is the list view in the middle -->
    <ListView 
        android:layout_width="match_parent"
        android:layout_weight="1"
        android:layout_height="0dip">
    </ListView>

    <!-- This is a bunch of buttons at the bottom -->
    <RelativeLayout 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingTop="5dip"
        android:gravity="bottom">
    </RelativeLayout>

</LinearLayout>