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

    xiaoxiao2021-03-25  132

    今天有一个简单小需求,就是我们的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.看看我们的效果图:

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

    转载请注明原文地址: https://ju.6miu.com/read-7837.html

    最新回复(0)