前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android-PullToRefresh自动加载更多

Android-PullToRefresh自动加载更多

作者头像
夏洛克的猫
发布2018-10-18 14:24:42
1.1K0
发布2018-10-18 14:24:42
举报
文章被收录于专栏:移动开发移动开发

Android-PullToRefresh(github地址)是个十分方便的下拉刷新库(也有上拉加载的功能),各个app中常见到滑到底部自动加载的功能,这里提供一个简单的实现思路:

代码语言:javascript
复制
    <com.handmark.pulltorefresh.library.PullToRefreshListView    
        xmlns:ptr="http://schemas.android.com/apk/res-auto"
        android:id="@+id/id_pull_to_refresh_listview"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:cacheColorHint="@color/gray_light"
        android:divider="@color/gray_light"
        android:dividerHeight="@dimen/spacing_normal"
        android:fadingEdge="none"
        android:fadingEdgeLength="0dp"
        android:scrollingCache="false"
        ptr:ptrAnimationStyle="flip"
        ptr:ptrHeaderTextAppearance="?android:attr/textAppearanceMedium" />
代码语言:javascript
复制
mRefreshListView=(PullToRefreshListView)findViewById(R.id.id_pull_to_refresh_listview);
mRefreshListView.setMode(PullToRefreshBase.Mode.PULL_FROM_START);
footer = LayoutInflater.from(getActivity()).inflate(R.layout.footer,null,false);
mRefreshListView.getRefreshableView().addFooterView(footer);
//该回调会在滑到最后一个可见view的时候会被调用,此时我们让添加的footer可见
mRefreshListView.setOnLastItemVisibleListener(new PullToRefreshBase.OnLastItemVisibleListener() {
            @Override
            public void onLastItemVisible() {
                footer.setVisibility(View.VISIBLE);
                //后面执行加载数据的请求,完成后调用footer.setVisibility(View.GONE)
            }
        });
代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>

<!--R.layout.footer -->
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:padding="5dp"
    android:text="正在加载中...."
    android:textSize="@dimen/common_text_size" />

注意:如果footer.setVisibility(View.GONE),扔占据空间的话给他设置一个父view

思路比较简单,希望对家有帮助

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2015年12月22日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档