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

转载请注明出处: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实现有删除动画的多选删除功能不行嘛!!!
好吧,既然你们产品经理沉迷于这种效果,咱们就做做吧…

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

AutoLoadListView的github项目地址

  • 6
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 11
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值