Android中ListView没有数据的时候,显示为一张图片

来源:互联网 发布:手机淘宝客服是卖家吗 编辑:程序博客网 时间:2024/06/06 14:11

今天有一个简单小需求,就是我们的ListView的数据列表,当没有数据时候,需要显示一张图片,当然这也符合用户的体验,

1.布局文件:

<?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:orientation="vertical">    <ListView        android:id="@+id/activity_order_new_pl"        android:layout_width="match_parent"        android:layout_height="match_parent" />    <ImageView        android:id="@+id/fragment_order_new_empty_view"        android:layout_width="match_parent"        android:layout_height="match_parent"        android:src="@drawable/no_data"/></LinearLayout>

2.使用:

 //设置空列表的时候,显示为一张图片 listView.setEmptyView(bindView(R.id.fragment_order_new_empty_view));

3.需要显示的图片(图片有点丑):
这里写图片描述

4.看看我们的效果图:
这里写图片描述

这样实现是不是很简单呢!
本人菜鸟一个,有什么不对的地方希望大家指出评论,大神勿喷,希望大家一起学习进步!

1 0
原创粉丝点击