android - 如何设置一个空的 ListView 的背景图片?

标签 android image listview background

如何设置这样的 ListView 背景。 我想在记录数为0时出现

enter image description here

最佳答案

ListView 中有特殊方法 - setEmptyView() .您可以找到使用它的示例 herehere .

更新:第二个链接现在不可用。这是文章的引述:

When you set a ListView’s “empty view” programmatically, you can end up scratching your head as to why your empty view actually doesn’t appear when the list is empty.
If this happens, then what you forgot is that you must manually add your empty view to your view hierarchy, cos ListView won’t do it for you. Although it’s obvious when you think about it, the documentation doesn’t mention this detail, and Googling shows at least one person had the problem.

Here’s the code with the lines that it’s all too easy to forget at numbers 4 and 5…

TextView emptyView = new TextView(context);
emptyView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
emptyView.setText(“This appears when the list is empty”);
emptyView.setVisibility(View.GONE);
((ViewGroup)list.getParent()).addView(emptyView);
list.setEmptyView(emptyView);

关于android - 如何设置一个空的 ListView 的背景图片?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6251109/

相关文章:

listview - 从 ListView 中 flutter 删除项目

android - 如何将我的 Android 2.2 应用迁移到 Google TV

php - 当需要多种尺寸时,图像应该如何存储?

python - 从 numpy 图像中提取彩色线

android - ListView 的 getChildCount 方法不返回可见项目数的准确计数

android - ListView 在 Scroll 上改变数据

android - 从 Firebase 读取多个值并放置在折线图中

Android工具栏白色与黑色

android - 可重用组件 : toolbar like in astro app for Android

java - 如何将图像从android发送到servlet然后存储