Android 如何将小部件放置在listview的上方和下方?

Android 如何将小部件放置在listview的上方和下方?,android,listview,layout,Android,Listview,Layout,我有一个列表视图,想把东西放在上面(y轴上)和下面(y轴上),包括图像、文本视图和一行按钮。下面是我正在创建的内容的简化版本。不幸的是,列表覆盖了标题(即z轴上方),因此标题文本不可见,而不是位于下方(y轴上) 如果您的目标是Android 1.6及更高版本,请在列表视图的现有属性中添加一个Android:layout_down=“@id/header” 如果您仍然以Android 1.5为目标,则需要在“@+id/header”下面设置Android:layout_,并可能从当前的Androi

我有一个列表视图,想把东西放在上面(y轴上)和下面(y轴上),包括图像、文本视图和一行按钮。下面是我正在创建的内容的简化版本。不幸的是,列表覆盖了标题(即z轴上方),因此标题文本不可见,而不是位于下方(y轴上)


如果您的目标是Android 1.6及更高版本,请在
列表视图
的现有属性中添加一个
Android:layout_down=“@id/header”

如果您仍然以Android 1.5为目标,则需要在“@+id/header”下面设置
Android:layout_,并可能从当前的
Android:id=“@+id/header”
文本视图中删除
+
符号


RelativeLayout
,从1.6开始,只要ID值的第一次出现具有
+
符号,就支持对其他小部件的正向引用。

我无法在Android 1.5中使用相对布局,但我确实使用了线性布局。以下是我的解决方案:

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

    <TextView android:id="@+id/header" 
        android:text="header"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="0"
        />
    <ListView  android:id="@+id/list_view" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:background="#ff9999ff"
        android:layout_weight="1"/>

    <TextView android:id="@+id/footer" 
        android:text="footer"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="0"
        />
</LinearLayout>

这应该使用RelativeLayout:

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

    <TextView android:id="@+id/header" 
        android:text="header"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" />

    <TextView android:id="@+id/footer" 
        android:text="footer"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_alignParentBottom="true"/>

    <ListView android:id="@id/android:list" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:layout_below="@id/header"
        android:background="#ff9999ff"/>

</RelativeLayout>


编辑:删除了建议的android:orientation

您只需在线性布局内的列表中添加权重1,其他文本视图/按钮/等不需要任何权重值

以下是一个例子:

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

    <TextView android:id="@+id/header" 
        android:text="header"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="0"
        />
    <ListView  android:id="@+id/list_view" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:background="#ff9999ff"
        android:layout_weight="1"/>

    <TextView android:id="@+id/footer" 
        android:text="footer"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_weight="0"
        />
</LinearLayout>
<?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">

    <TextView android:id="@+id/header" 
        android:text="header"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" />

    <TextView android:id="@+id/footer" 
        android:text="footer"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent" 
        android:layout_alignParentBottom="true"/>

    <ListView android:id="@id/android:list" 
        android:layout_height="fill_parent" 
        android:layout_width="fill_parent"
        android:layout_below="@id/header"
        android:background="#ff9999ff"/>

</RelativeLayout>