android - 将页脚设置为 ListView

标签 android

大家。 你能帮我设置 ListView 的页脚吗?我已经在布局中描述了页脚,然后:

View footer = getLayoutInflater().inflate(R.layout.bottom, getListView(), false);
getListView().addFooterView(footer);

但是没有出现... 能举个例子吗?我还需要动态设置页脚的高度。下面是页脚的代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#87ceeb"
    >
<TextView android:id="@+id/loading"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent"
                  android:textColor="#000000"
                  android:textStyle="bold"
                  android:text="Loading..."/>
</LinearLayout>

最佳答案

这可能有几个原因, 你添加代码了吗

getListView().addFooterView(页脚);在 ListView 的 setAdapter 之前?如果是。

xml布局可能有问题, 如果您的 ListView 是 wrap_content 并且您的页脚布局具有 fill_parent ,则页脚可能不会出现,除非您的页脚布局的 TextView 中有一些文本。

更改 ListView layout_width="fill_parent"和页脚布局的 layout_width="fill_parent"

要快速检查 ,请为您的页脚布局提供背景颜色并查看其位置。 希望对您有所帮助。

关于android - 将页脚设置为 ListView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5267823/

相关文章:

java - Android 绘图、删除和撤消操作

javascript - 为 Android 应用程序创建动态雷达

android - Android Toast 可以比 Toast.LENGTH_LONG 长吗?

android - 为什么 `setPositiveButton` 总是返回 -1 以及如何获取选定的索引?

Android Studio 无法获取 - 连接被拒绝 : connect

android - jquery 手机 + phonegap : search bar too wide

java - 无法解析符号 'AuthUI'

php - 在 Android 中显示来自 MySQL 数据库的数据,类似于 Twitter Feed

android - 如何在android jetpack compose ui中实现水平滚动?

java - Android JNI GetMethodID() 失败