【凯子哥带你夯实应用层】还在用XListView?试试更漂亮的AutoLoadListView吧!

来源:互联网 发布:知乎 杨洋 油腻 编辑:程序博客网 时间:2024/04/29 23:47

转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992

关于上拉刷新和下拉加载,已经有不少的解决方案了,XListView和PullToRefresh应该是被广为熟知的开源项目,项目很棒,可以解决我们的需求。但是,今天咱们用一种更简单的方式,来实现上拉刷新和下拉加载功能,我叫它AutoLoadListView~

先来一张效果图。

效果

刷新效果使用19版本之后的v4兼容包的SwipeRefreshLayout实现,效果很漂亮,而自动加载下一页的跳动效果,则是使用了另外一个开源项目JumpingBeans,这跳动的省略号,是不是很赞呢?

下面简单介绍下使用方法

  • 布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:layout_width="match_parent"    android:layout_height="match_parent" >    <android.support.v4.widget.SwipeRefreshLayout        android:id="@+id/swipe_refresh"        android:layout_width="match_parent"        android:layout_height="match_parent" >        <com.socks.autoload.AutoLoadListView            android:id="@+id/listview"            android:layout_width="match_parent"            android:layout_height="match_parent" >        </com.socks.autoload.AutoLoadListView>    </android.support.v4.widget.SwipeRefreshLayout></RelativeLayout>
  • 刷新。我们实现刷新需要实现SwipeRefreshLayout.OnRefreshListener接口,然后在onRefresh()实现刷新逻辑即可
public void onRefresh()
  • 加载下一页。我们需要添加一个接口,然后在回调中实现我们的加载任务即可
listView.setOnLoadNextListener(new OnLoadNextListener() {            @Override            public void onLoadNext() {                handler.sendEmptyMessageDelayed(MSG_LOAD_MORE, 3000);            }        });

是不是用起来很简单捏?


有的同学可能问了,我要是想要侧滑删除咋办?
囧…
又不是只有这一种交互效果!为啥抓着这种效果不放啊!用前面介绍的【凯子哥带你夯实应用层】使用ActionMode实现有删除动画的多选删除功能不行嘛!!!
好吧,既然你们产品经理沉迷于这种效果,咱们就做做吧…

  • 第一步,找到我们的ZListView,不明真相的同学,请戳【Android界面实现】ZListView,一个最强大的刷新、加载、滑动删除的ListView控件(一)
  • 把除了ZlistView之外的所有类都拷贝到我们的项目
  • 用AutoLoadListView替代ZListView即可

看下效果图,也还ok啊~但是因为是demo,所以很多业务没处理,这个就需要大家根据自己的需求去改源码了,开源项目的好处不就在此么~

AutoLoadListView的github项目地址

6 0