今日份学习,新闻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();