zoukankan      html  css  js  c++  java
  • 上拉加载下拉刷新

    老方法,先上效果图:

    1.加入下拉刷新 上拉加载的依赖

    1 //下拉刷新 上拉加载
    2 implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.0.4-7'
    3 implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.0.4-7'

    2.控件的布局文件代码,以下的LinearLayout是内容部分,直接替换即可。

     1 <com.scwang.smartrefresh.layout.SmartRefreshLayout
     2         android:id="@+id/srl_control"
     3         android:layout_width="match_parent"
     4         android:layout_height="match_parent"
     5         app:srlAccentColor="@color/colorTransparent"
     6         app:srlPrimaryColor="@color/colorTransparent"
     7         app:srlEnablePreviewInEditMode="true">
     8 
     9         <com.scwang.smartrefresh.layout.header.ClassicsHeader
    10             android:layout_width="match_parent"
    11             android:layout_height="wrap_content"/>
    12 
    13 
    14         <LinearLayout
    15             android:background="@color/colorTheme"
    16             android:layout_width="match_parent"
    17             android:layout_height="610dp"/>
    18 
    19         <com.scwang.smartrefresh.layout.footer.ClassicsFooter
    20             android:layout_width="match_parent"
    21             android:layout_height="wrap_content"/>
    22 
    23     </com.scwang.smartrefresh.layout.SmartRefreshLayout>

    3.下拉和上拉的事件我封装在私有类中,直接在onCreate调用该类

     1 private void initSmartRefresh(){
     2         //下拉刷新
     3         refreshLayout.setOnRefreshListener(new OnRefreshListener() {
     4             @Override
     5             public void onRefresh(RefreshLayout refreshlayout) {
     6                 refreshlayout.setEnableRefresh(true); //启用刷新
     7                 //刷新的事件逻辑
     8                 try {
     9                     Thread.sleep(3000);
    10                     refreshlayout.finishRefresh();//结束刷新
    11                 } catch (InterruptedException e) {
    12                     e.printStackTrace();
    13                 }
    14             }
    15         });
    16 
    17         //上拉加载
    18         refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() {
    19             @Override
    20             public void onLoadmore(RefreshLayout refreshlayout) {
    21                 refreshlayout.setEnableLoadmore(true);//启用加载
    22                 //加载的事件逻辑
    23                 try {
    24                     Thread.sleep(3000);
    25                     refreshlayout.finishLoadmore(); //结束加载
    26                 } catch (InterruptedException e) {
    27                     e.printStackTrace();
    28                 }
    29             }
    30         });
    31     }
  • 相关阅读:
    面向接口编程详解(二)——编程实例
    面向接口编程详解(一)——思想基础
    设计模式之面向接口编程
    EF数据注解
    很多人不知道可以使用这种 key 的方式来对 Vue 组件时行重新渲染
    这是最新的一波Vue实战技巧,不用则已,一用惊人
    Node.js 进阶-你应该知道的 npm 知识都在这
    Vue响应式原理
    eslint规则
    简述vue-cli中chainWebpack的使用方法
  • 原文地址:https://www.cnblogs.com/Mr-Deng/p/11586105.html
Copyright © 2011-2022 走看看