[Link] Android smart pull-down refresh framework - SmartRefreshLayout
http://blog.csdn.net/yunyu5120/article/details/74451961
Use the SmartRefreshLayout control to achieve the most advanced loading and refreshing effects
The most original effect:
<com.scwang.smartrefresh.layout.SmartRefreshLayout android:id="@+id/mRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent"> //Adding this is to pull down to refresh the initial head effect <com.scwang.smartrefresh.layout.header.ClassicsHeader android:layout_width="match_parent" android:layout_height="wrap_content" /> <RecyclerView android:id="@+id/mRecyclerView"
android:layout_width="match_parent" android:layout_height="match_parent" />
//This is the effect of the bottom pull-up loading, <com.scwang.smartrefresh.layout.footer.ClassicsFooter android:id="@+id/mClassicsFooter" android:layout_width="match_parent" android:layout_height="wrap_content" /> </com.scwang.smartrefresh.layout.SmartRefreshLayout>
Code:
private RefreshLayout refreshLayout; refreshLayout=(RefreshLayout)findViewById(R.id.mSwipeRefreshLayout); refreshLayout.setOnRefreshListener(new OnRefreshListener() { @Override public void onRefresh(RefreshLayout refreshlayout) { //refresh new Handler().postDelayed(new Runnable() { @Override public void run() { currpage = 1; // stop refreshing when finished refreshData(); } }, 100); refreshlayout.finishRefresh(1000); } }); refreshLayout.setOnLoadmoreListener(new OnLoadmoreListener() { @Override public void onLoadmore(final RefreshLayout refreshlayout) { refreshlayout.finishLoadmore(1000); new Handler().postDelayed(new Runnable() { @Override public void run() { switch (status) { case 0: currpage++; new StartAsyncTask().execute("initPostInfo"); mAdapter.setNewData(mDetailList); mAdapter.loadMoreComplete(); break; case 1: currpage++; new StartAsyncTask().execute("initPostInfo"); mAdapter.setNewData(mDetailList); mAdapter.loadMoreEnd(); break; case 2: mAdapter.loadMoreFail(); break; } } }, 100); } });
If the head and bottom do not need such effects, you can remove them, and then set the desired effects by yourself. If the project does not require special requirements, such effects have already met most of the functional requirements.
You can also set global effects
In this way, the drop-down effect of the entire project can be achieved
public class MyApp extends Application{ static {//static code segment can prevent memory leaks //Set the global Header builder SmartRefreshLayout.setDefaultRefreshHeaderCreater(new DefaultRefreshHeaderCreater() { @Override public RefreshHeader createRefreshHeader(Context context, RefreshLayout layout) { layout.setPrimaryColorsId(R.color.colorPrimary, android.R.color.white);//Set theme color globally // return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Translate);//Parallel movement characteristics: the most common, the height of HeaderView will not change, // return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.FixedBehind);//Fixed at the back Features: will not move up and down, HeaderView height will not change (similar to WeChat browser effect) // return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.FixedFront);//Fixed in front features: will not move up and down, HeaderView height will not change return new ClassicsHeader(context).setSpinnerStyle(SpinnerStyle.Scale);//Stretching deformation characteristics: When pulling down and up (HeaderView height changes), the OnDraw event will be triggered automatically } }); //Set the global Footer builder SmartRefreshLayout.setDefaultRefreshFooterCreater(new DefaultRefreshFooterCreater() { @Override public RefreshFooter createRefreshFooter(Context context, RefreshLayout layout) { //Specify as classic Footer, default is BallPulseFooter // return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Translate); // return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.FixedBehind); // return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.FixedFront); return new ClassicsFooter(context).setSpinnerStyle(SpinnerStyle.Scale); } }); } @Override public void onCreate() { super.onCreate(); } }
The following layout can add a header ad slot to the list,
<com.scwang.smartrefresh.layout.SmartRefreshLayout android:id="@+id/mRefreshLayout" android:layout_width="match_parent" android:layout_height="match_parent" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" > <pl.droidsonroids.gif.GifImageView android:layout_width="match_parent" android:layout_height="150dp" android:scaleType="centerCrop" android:src="@mipmap/gif_header_repast"/> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <TextView android:layout_width="match_parent" android:layout_height="100dp" android:gravity="center" android:text="I am the banner that boos asked to add"/> <android.support.v7.widget.RecyclerView android:id="@+id/mRecyclerView" android:layout_width="match_parent" android:layout_height="match_parent" /> </LinearLayout> </com.scwang.smartrefresh.layout.SmartRefreshLayout>