Android-PullRefreshLayout

来源:互联网 发布:开票软件的控制台 编辑:程序博客网 时间:2024/05/17 02:29

项目地址:Android-PullRefreshLayout

简介:基于SwipeRefreshLayout,通吃所有的AbsListView、RecyclerView


Android-PullRefreshLayout

基于SwipeRefreshLayout下拉刷新、上拉加载。支持所有的AbsListViewRecycleView

特点

  • layout中使用,支持AbsListView所有的 xml 属性
  • 支持自动下拉刷新,什么用呢?比如进入界面时,只需要调用autoRefresh()方法即可,同时下拉刷新回调函数将会被调用。
  • 上拉加载支持自定义View或设置加载文字、动画
  • 轻松设置Adapter空数据视图,默认为TextView支持更文字,也可自定义View
  • 对于简单的界面,如只有ListView可以继承 app 包中Fragment轻松搞定

效果图

使用

仔细看listSelector属性,效果见sample

<com.mylhyl.prlayout.SwipeRefreshListView xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    android:id="@+id/swipeRefresh"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:listSelector="@drawable/selector_list"    tools:context=".app.ListViewXmlFragment" />

设置上拉加载,更多方法见 IFooterLayout

        IFooterLayout footerLayout = swipeRefreshListView.getFooterLayout();        footerLayout.setFooterText("set 自定义加载");        footerLayout.setIndeterminateDrawable(getResources().getDrawable(R.drawable.footer_progressbar));

        pr:footer_text="数据正在加载中"        pr:footer_indeterminate_drawable="@drawable/footer_progressbar"

自定义上拉加载

  • 方式一:注意此方法必须在setOnListLoadListener之前调用
        getSwipeRefreshLayout().setFooterResource(R.layout.swipe_refresh_footer);
  • 方式二:xml 属性
        pr:footer_layout="@layout/swipe_refresh_footer"
  • 方式三:继承重写getFooterResource()方法
        public class MySwipeRefreshGridView extends SwipeRefreshGridView {            @Override            protected int getFooterResource() {                return R.layout.swipe_refresh_footer;            }        }

设置 adapter 空数据视图文字

        swipeRefreshListView.setEmptyText("数据呢?");

自定义 adapter 空数据视图

        ImageView emptyView = new ImageView(getContext());        emptyView.setImageResource(R.mipmap.empty);        swipeRefreshGridView.setEmptyView(emptyView);

调用autoRefresh自动刷新,那么注册ListView长按事件怎么办?好办提供了方法getScrollView()取出 又有问题了既然能取到ListViewSwipeRefreshLayout是不是也可以取到呢? 答案是肯定的,方法getSwipeRefreshLayout取出,你可以随心所欲了,设置下拉圆圈的颜色、大小等。 关于更多公开方法见ISwipeRefresh

使用 Gradle 构建时添加一下依赖即可:

compile 'com.mylhyl:pullrefreshlayout:1.2.3'

如果使用 eclipse可以点击这里下载 jar 包

但是由于jar不能打包res原因,将影响xml属性的使用,手动拷贝attrs到自己的项目中. 也可以clone源码,然后在 eclipse 中用library方式引用

下载 APK 体验

1.0.0
  • 初始版本
1.1.0
  • 修改类访问权
1.2.0
  • 优化内部业务逻辑
1.2.1
  • 修复嵌套ViewPage引起的冲突
1.2.2
  • 增加attrs属性 可在xml中配置footer参数
1.2.3
  • 子视图上滑冲突方案由OnScrollListener改为重写canChildScrollUp

2 0
原创粉丝点击