故事背景
自从Android Material Design出来之后,以其优雅酷炫的效果深受广大用户的喜爱,我个人也非常喜欢其漂亮的界面,特别是SwipeRefreshLayout,呵呵看脸的世界ing
言归正传最近有个项目需要用到SwipeRefreshLayout嵌套一个listView,该listview不需要上拉加载,就是只需要简单的下拉刷新即可,于是二话不说,直接SwipeRefreshLayout嵌套ListView,嗯,效果完美,布局代码如下
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/listview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"/>
</android.support.v4.widget.SwipeRefreshLayout> 但是考虑到当listview没有数据的话应该显示一个提示,比如“暂无数据,下拉刷新”之类的提示,于是把布局改成下面这样:
<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe

本文探讨了在Android开发中如何优雅地实现SwipeRefreshLayout与ListView的嵌套,并解决了空数据时显示提示信息的问题。通过调整布局结构,最终实现了流畅的下拉刷新体验。
最低0.47元/天 解锁文章
8514





