Android 刷新框架SmartRefreshLayout

本文详细介绍了Android的SmartRefreshLayout框架,包括实例展示、属性表格、以及如何通过Java和XML代码设置SmartRefreshLayout、ClassicsHeader和ClassicsFooter。
摘要由CSDN通过智能技术生成

Android 刷新框架SmartRefreshLayout


依赖

implementation 'com.scwang.smartrefresh:SmartRefreshLayout:1.1.0-alpha-14'
implementation 'com.scwang.smartrefresh:SmartRefreshHeader:1.1.0-alpha-14'//没有使用特殊Header,可以不加这行
implementation 'com.android.support:appcompat-v7:25.3.1'//版本 23以上(必须)

实例

xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <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:id="@+id/head"
            android:layout_width="match_parent"
            android:layout_height="match_parent">
        </com.scwang.smartrefresh.layout.header.ClassicsHeader>
        <ListView
            android:id="@+id/lv1"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </ListView>

        <com.scwang.smartrefresh.layout.footer.ClassicsFooter
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        </com.scwang.smartrefresh.layout.footer.ClassicsFooter>
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>

</LinearLayout>

activity


public class MainActivity extends AppCompatActivity {

    private ListView lv1;
    private List<String> list = new ArrayList<>();
    private ArrayAdapter arrayAdapter;
    private ClassicsHeader head;
    private SmartRefreshLayout refreshLayout;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initData();
    }

    private void initData() {
        for (int i = 0; i < 100; i++) {
            list.add("item  " + i);
        }
        arrayAdapter.notifyDataSetChanged();
    }

    private void initView() {
        lv1 = (ListView) findViewById(R.id.lv1);
        head = (ClassicsHeader) findViewById(R.id.head);

        arrayAdapter = new ArrayAdapter(MainActivity.this, R.layout.support_simple_spinner_dropdown_item, list);
        lv1.setAdapter(arrayAdapter);

        refreshLayout = (SmartRefreshLayout) findViewById(R.id.refreshLayout);
        
        refreshLayout.setOnMultiPurposeListener(new SimpleMultiPurposeListener(){
            @Override
            public void onLoadMore(@NonNull RefreshLayout refreshLayout) {
                super.onLoadMore(refreshLayout);
                Log.e("######加载",2+"");
                for (int i = 500; i < 600; i++) {
                    list.add("item  " + i);
                }
                arrayAdapter.notifyDataSetChanged();
                refreshLayout.finishLoadMore();
            }

            @Override
            public void onRefresh(@NonNull RefreshLayout refreshLayout) {
                super.onRefresh(refreshLayout);
                Log.e("######刷新",1+"");
                for (int i = 100; i < 200; i++) {
                    list.add("item  " + i);
                }
                arrayAdapter.notifyDataSetChanged();
                refreshLayout.finishRefresh();
            }
        });
    }
}


在这里插入图片描述

属性表格

Attributes

name format description
srlPrimaryColor color 主题颜色
srlAccentColor color 强调颜色
srlReboundDuration integer 释放后回弹动画时长(默认250毫秒)
srlFooterHeight dimension Footer的标准高度(dp)
srlHeaderInsetStart dimension Header的起始偏移量(dp)V1.0.5
srlFooterInsetStart dimension Footer的起始偏移量(dp)V1.0.5
srlDragRate float 显示拖动高度/真实拖动高度(默认0.5,阻尼效果)
srlHeaderMaxDragRate float Header最大拖动高度/Header标准高度(默认2,要求>=1)
srlFooterMaxDragRate float Footer最大拖动高度/Footer标准高度(默认2,要求>=1)
srlHeaderTriggerRate float Header触发刷新距离 与 HeaderHeight 的比率(默认1)
srlFooterTriggerRate float Footer触发加载距离 与 FooterHeight 的比率(默认1)
srlEnableRefresh boolean 是否开启下拉刷新功能(默认true)
srlEnableLoadMore boolean 是否开启加上拉加载功能(默认false-智能开启)
srlEnableAutoLoadMore boolean 是否监听列表惯性滚动到底部时触发加载事件(默认true)
srlEnableHeaderTranslationContent boolean 拖动Header的时候是否同时拖动内容(默认true)
srlEnableFooterTranslationContent boolean 拖动Footer的时候是否同时拖动内容(默认true)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值