前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Android智能刷新加载框架-SmartRefreshLayout

Android智能刷新加载框架-SmartRefreshLayout

作者头像
饮水思源为名
发布2018-09-06 12:52:13
2K0
发布2018-09-06 12:52:13
举报
文章被收录于专栏:Android小菜鸡

框架:

  SmartRefreshLayout是目前为止笔者用过的嘴方便的刷新加载组件,它对下拉刷新功能进行系统的拆分、组合,主要由四个部分组成:

  • RefreshLayout 下拉的基本功能,包括布局测量、滑动事件处理、参数设定等等
  • RefreshContent 对不同内容的统一封装,包括判断是否可滚动、回弹判断、智能识别
  • RefreshHeader 下拉头部的实现和显示
  • RefreshFooter 上拉底部的实现和显示

UML关系类图:

  通过SmartRefreshLayout框架,你可以在一个稳定强大的下拉布局中实现自己项目需求的 Header ,不用去关心滑动事件处理,不用关心子控件的回弹和滚动边界,只需关注自己真正的项目需求Header的样子和动画。

使用方法:

  1. 在xml中不居中部署:
代码语言:javascript
复制
  <LinearLayout
        android:background="#f2f2f2"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <com.scwang.smartrefresh.layout.SmartRefreshLayout
            android:id="@+id/refreshLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
            <com.scwang.smartrefresh.layout.header.ClassicsHeader
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerview"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
            <com.scwang.smartrefresh.layout.footer.ClassicsFooter
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />
        </com.scwang.smartrefresh.layout.SmartRefreshLayout>
    </LinearLayout>
  1. 在java中获取RefreashLayout实例 refreshLayout=findViewById(R.id.refreshLayout);
  2. 初始化RefreashLayout
代码语言:javascript
复制
 refreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshlayout) {
                mPresenter.loadNextMessage("refresh",bean.getId());
            }
        });
        refreshLayout.setOnLoadMoreListener(new OnLoadMoreListener() {
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                mPresenter.loadNextMessage("loadmore",bean.getId());
            }
        });
        refreshLayout.autoRefresh();
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018.07.27 ,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 框架:
  • UML关系类图:
  • 使用方法:
相关产品与服务
智能识别
腾讯云智能识别(Intelligent Identification,II)基于腾讯各实验室最新研究成果,为您提供视频内容的全方位识别,支持识别视频内的人物、语音、文字以及帧标签,对视频进行多维度结构化分析。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档