"top bar"和 "bottom bar"之间的 ListView 的 Android 布局

标签 android android-layout android-linearlayout footer android-relativelayout

我正在尝试构建一个布局,其中屏幕顶部有一个 TextView ,屏幕底部有一个底栏。 这些 View 中的每一个都应该固定在适当的位置,并且在这两个 View 之间应该是一个 ListView。

TOPBAR
LISTVIEW (scrollable)
BOTTOM BAR

我的布局(见下文)几乎 有效:顶部和底部组件保持固定, ListView 滚动。 “问题”是我的 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>

最佳答案

这里有一个简单的建议。制作一个新的 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>

关于 "top bar"和 "bottom bar"之间的 ListView 的 Android 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3989883/

相关文章:

java - Android Studio LoginActivity with MySQL - 尝试对网络服务进行身份验证

android - 如何在回到上一个ListView的同时保持ListView的位置?

java - 如何才能停止我正在运行的代码?

android - 在 onCreateView() 方法之外访问 View

android - 如何在 Android 中为不同的布局加载不同的可绘制资源?

Android LinearLayout 填充中间

android - 不适用于 Xtify 入门示例

android - ImageView 在 Camera Surface View 后面移动

android - 缩放背景图像以包装布局内容

android - 如何创建一个 Button 至少与 TextView 一样长的布局?