Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/200.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何允许Android ListView在TableLayout中使用剩余空间_Android - Fatal编程技术网

如何允许Android ListView在TableLayout中使用剩余空间

如何允许Android ListView在TableLayout中使用剩余空间,android,Android,我试图使表中的ListView消耗所有可用的垂直空间减去EditText控件所需的空间 我在这里设置了我能想到的所有属性,以使其正常工作: <?xml version="1.0" encoding="utf-8"?> 我一定是遗漏了什么,因为结果是一个完全填充的水平面,但ListView和EditText的行为似乎都像它们的属性是包装内容一样。我似乎遗漏了顶部表格行上的属性android:layout\u weight。显然,任何超过2的东西都会消耗垂直不动产的其余部分

我试图使表中的ListView消耗所有可用的垂直空间减去EditText控件所需的空间

我在这里设置了我能想到的所有属性,以使其正常工作:

<?xml version="1.0" encoding="utf-8"?>



我一定是遗漏了什么,因为结果是一个完全填充的水平面,但ListView和EditText的行为似乎都像它们的属性是包装内容一样。

我似乎遗漏了顶部表格行上的属性android:layout\u weight。显然,任何超过2的东西都会消耗垂直不动产的其余部分。有人能解释一下为什么要对TableRows进行特殊处理吗?

不要在
ScrollView
中使用
ListView
,因为ListView管理自己的垂直滚动。这样做将终止
列表视图所做的所有优化


也不要对你自己的帖子发号施令。而是编辑您最初的问题或添加评论

使用TableLayout有什么特别的原因吗?我还不太熟悉如何使用它们,但您试图通过相对论实现的是简单的。另外,您不需要将ListView放在ScrollView中,ListView自己处理滚动。下面是一个示例,说明如何使用RelativeLayout实现此目的:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText
        android:id="@+id/message_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
        android:imeOptions="actionDone"
        android:alignParentBottom="true"
        />
    <ListView
        android:id="@+id/conversation"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FF0000"
        android:layout_above="@id/message_text"
        />
</RelativeLayout>


这样,您首先定义EditText以占用一定的空间(在本例中为wrap_内容)。然后,定义ListView,用fill\u parent填充剩余空间。在上面添加android:layout_=“@id/message_text”会将ListView的下边缘与EditText视图的上边缘对齐。

如果您已经解决了自己的问题,则完全可以回答该问题。您不需要将布局权重设置为2/4。如果它是唯一具有属性的元素,则可以为其指定值1。
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    <EditText
        android:id="@+id/message_text"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#00FF00"
        android:inputType="text|textAutoCorrect|textMultiLine|textImeMultiLine"
        android:imeOptions="actionDone"
        android:alignParentBottom="true"
        />
    <ListView
        android:id="@+id/conversation"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="#FF0000"
        android:layout_above="@id/message_text"
        />
</RelativeLayout>