Android 在listview之后的屏幕底部添加按钮

Android 在listview之后的屏幕底部添加按钮,android,Android,我试图在listview下方的屏幕底部中央添加“提交”按钮,但没有成功。有什么想法吗?我还添加了按钮代码。我相信在某个地方,家长正在掩盖整个屏幕 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layou

我试图在listview下方的屏幕底部中央添加“提交”按钮,但没有成功。有什么想法吗?我还添加了按钮代码。我相信在某个地方,家长正在掩盖整个屏幕

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

    <TextView
        android:id="@+id/question"
        android:layout_marginTop="20dip"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:paddingLeft="10dip"
        android:textSize="17dp"
        android:text="Please select the programs/episodes you watched last week for which you will submit response"
        android:textColor="#000"/>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:layout_marginTop="20dip"
        android:background="#f4f4f4">

        <ExpandableListView
            android:id="@+id/android:list"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:cacheColorHint="#00000000"/>

        <Button
            android:id="@+id/btn_New"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="20dp"
            android:text="Submit"
            android:width="170dp"
            android:layout_alignParentBottom="true" />

    </LinearLayout>
</LinearLayout>

您可以使用RelativeLayout和设置按钮

android:layout\u alignParentBottom=“true”


将列表视图设置为
android:layout\u over=“”

而不是将ExpandableListView的高度设置为
match\u parent
,将其权重设置为1,高度设置为0dp,这样将显示所有其他元素,ExpandableListView将占用剩余空间

<ExpandableListView
    android:id="@+id/android:list"
    android:layout_height="0dp"
    android:layout_weight="1"
    android:layout_width="match_parent"
    android:cacheColorHint="#00000000"/>

在布局中使用以下代码:

<?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:background="#f4f4f4"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/question"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="20dip"
        android:paddingLeft="10dp"
        android:paddingStart="10dp"
        android:text="Please select the programs/episodes you watched last week for which you will submit response"
        android:textColor="#000"
        android:textSize="17dp" />

    <ExpandableListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:cacheColorHint="#00000000" />

    <Button
        android:id="@+id/btn_New"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="Submit" />

</LinearLayout>

输出:


你能告诉我们它现在看起来是什么样子以及应该是什么样子吗?它可以工作,但如果你能解释一下你改变了什么以及为什么,那就太好了。在expandablelistview标签中的android:layout\u weight=“1”