• 每日学习


    今日份学习,新闻app当然得有上拉下拉了,所以smartRefreshLayout得好好学一下,

    <?xml version="1.0" encoding="utf-8"?>
    <com.scwang.smartrefresh.layout.SmartRefreshLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/srl_fresh"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.wen.asyl.pulltorefreshdemo.MainActivity">
    
        <android.support.v7.widget.RecyclerView
            android:id="@+id/rv_list"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:overScrollMode="never"
            android:background="#fff"/>
    
    </com.scwang.smartrefresh.layout.SmartRefreshLayout>
    recycleAdapter = new RecycleAdapter(MainActivity.this , mDatas );
    LinearLayoutManager layoutManager = new LinearLayoutManager(this);
    //设置布局管理器
    rvList.setLayoutManager(layoutManager);
    //设置为垂直布局,这也是默认的
    layoutManager.setOrientation(OrientationHelper.VERTICAL);
    //设置Adapter
    rvList.setAdapter(recycleAdapter);
    //设置 Header 为 贝塞尔雷达 样式
    srfresh.setRefreshHeader(new BezierRadarHeader(this).setEnableHorizontalDrag(true));
    //设置 Footer 为 球脉冲 样式
    srfresh.setRefreshFooter(new BallPulseFooter(this).setSpinnerStyle(SpinnerStyle.Scale));
    srfresh.setOnRefreshListener(new OnRefreshListener() {
        @Override
        public void onRefresh(final RefreshLayout refreshlayout) {
            //延时展示,延时2秒
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    initData();
                    recycleAdapter.refresh(mDatas);//刷新加载数据
                    refreshlayout.finishRefresh();
                }
            },2000);
    
        }
    });
    srfresh.setOnLoadMoreListener(new OnLoadMoreListener() {
        @Override
        public void onLoadMore(final RefreshLayout refreshlayout) {
            mHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    initData();
                    recycleAdapter.refresh(mDatas);
                    refreshlayout.finishLoadMore();
                }
            },2000);
    
        }
    });
    srfresh.setEnableLoadMore(true);
    srfresh.autoRefresh();
    作者:哦心有
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    1051 Wooden Sticks(贪心-3)
    97 等价交换(贪心-2)
    python文件操作
    python学习-day 2
    python学习-day 1
    Python 测试题目-1
    Python list和dict方法
    Python 字符串
    while循环语句
    Python if判断语句
  • 原文地址:https://www.cnblogs.com/haobox/p/14909312.html
Copyright © 2020-2023  润新知