美文网首页
快速使用开源库实现下拉刷新----PullRefreshLayo

快速使用开源库实现下拉刷新----PullRefreshLayo

作者: 破荒之恋 | 来源:发表于2016-12-27 13:13 被阅读1133次

下拉刷新

介绍android-PullRefreshLayout开源库的使用:

添加依赖库

dependencies {
    compile 'com.baoyz.pullrefreshlayout:library:1.2.0'
}

在Xml中加入使用

 <com.baoyz.widget.PullRefreshLayout
    android:id="@+id/swipeRefreshLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- ListView、ScrollView、RecyclerView、Other 多种-->
    <ListView
        android:id="@+id/list_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:scrollbars="none" >
    </ListView>
</com.baoyz.widget.PullRefreshLayout>

代码中引用刷新

 PullRefreshLayout layout = (PullRefreshLayout) findViewById(R.id.swipeRefreshLayout);
    layout.setOnRefreshListener(new PullRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            layout.postDelayed(new Runnable() {
                @Override
                public void run() {
                
               // 刷新3秒完成
                    layout.setRefreshing(false);
                }
            }, 3000);
        }
    });

设置下拉刷新的样式

下拉刷新时刷新头的样式可设置为这几种: MATERIAL、CIRCLES、 WATER_DROP、RING and SMARTISAN.设置方法如下

layout.setRefreshStyle(PullRefreshLayout.STYLE_CIRCLES);

还有几种样式,改变颜色,自定义样式等参考下面链接

https://github.com/baoyongzhang/android-PullRefreshLayout

效果图:
https://raw.githubusercontent.com/baoyongzhang/android-PullRefreshLayout/master/demo.gif

相关文章

网友评论

      本文标题:快速使用开源库实现下拉刷新----PullRefreshLayo

      本文链接:https://www.haomeiwen.com/subject/lxzsvttx.html