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

时间:2015-05-07 08:05:08

标签: android

我正在尝试添加"提交"列表视图下方屏幕底部中心的按钮但没有运气。任何的想法?我还在其中添加了按钮代码。我相信fill_parent正在掩盖整个屏幕

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

2 个答案:

答案 0 :(得分:2)

在布局中使用以下代码:

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

输出:

enter image description here

答案 1 :(得分:0)

您可以使用RelativeLayout并按钮设置

android:layout_alignParentBottom="true"

将列表视图设置为android:layout_above="<YOUR BUTTON ID>"