在"顶栏"和"底栏"之间使用ListView的Android布局

use*_*146 12 android footer android-layout android-linearlayout android-relativelayout

我正在尝试构建一个布局,其中屏幕顶部有一个文本视图,屏幕底部有一个底部栏.这些视图中的每一个都应保持固定,并且在2之间应该是ListView.

TOPBAR
LISTVIEW (scrollable)
BOTTOM BAR
Run Code Online (Sandbox Code Playgroud)

我的布局(见下文)几乎可以工作:顶部和底部组件保持固定,列表视图滚动."问题"是我的ListView的最后一行仍隐藏在底栏后面.

有关如何调整布局的任何建议?

谢谢!

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
    <LinearLayout
            android:layout_alignParentTop="true"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            >
        <TextView
                android:background="@drawable/blackgrad"
                android:gravity="center"
                android:id="@+id/title"
                android:layout_height="50dip"
                android:layout_width="fill_parent"
                android:text="blah blah"
                android:textColor="#ffffff"
                android:textSize="18sp"
                />
        <ListView
                android:background="#ffffff"
                android:cacheColorHint="#ffffffff"
                android:id="@android:id/list"
                android:layout_height="fill_parent"
                android:layout_width="fill_parent"
                />
    </LinearLayout>
    <LinearLayout
            android:background="#efefef"
            android:layout_alignParentBottom="true"
            android:layout_centerHorizontal="true"
            android:layout_width="fill_parent"
            android:layout_height="50dip"
            android:orientation="horizontal">
        <Button
                android:layout_height="wrap_content"
                android:id="@+id/back"
                android:text="Back"
                android:layout_width="wrap_content" />

        <Button
                android:layout_height="wrap_content"
                android:id="@+id/home"
                android:text="Home"
                android:layout_width="wrap_content" />

        <Button
                android:layout_height="wrap_content"
                android:id="@+id/next"
                android:text="Next"
                android:layout_width="wrap_content" />


    </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

glr*_*glr 29

这是一个简单的建议.制作一个新的XML,并使用它.

<?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">
    <TextView
        android:text="Header"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"/>
    <ListView
        android:id="@android:id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"/>
    <TextView
        android:text="Footer"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_gravity="bottom"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)


Fal*_*rri 5

OPs布局的问题在于第一个线性布局设置为android:layout_height="fill_parent"将导致第一个线性布局填充父级.它不知道您将添加更多视图.您需要做的是按照知道其大小的顺序添加视图.所以你知道顶部标准杆和底部标尺的大小,你可以将它们添加为android:layout_height="wrap_content".然后添加listview,因为它的大小在编译时是未知的.