综合了一下hongyang和loader的RecycleView的所有场景用法:
1.ListView列表分页用法核心代码:
private void createAdapter(){ mAdapter = new RecycleAdapter1(this); LinearLayoutManager mLinearLayoutManager1 = new LinearLayoutManager(this); mLinearLayoutManager1.setOrientation(OrientationHelper.VERTICAL); recyclerView.setLayoutManager(mLinearLayoutManager1); recyclerView.setAdapter(mAdapter); }
效果如下图:
2.GridView列表分页用法核心代码:
private void createAdapter(){ mAdapter = new RecycleAdapter2(this); recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); recyclerView.setAdapter(mAdapter); }
效果如下图:
3.ListView列表AddHeadAndAddFooter用法核心代码:
private void createAdapter() { ll_header = (LinearLayout) View.inflate(this, R.layout.activity_addheader, null); ll_footer = (LinearLayout) View.inflate(this, R.layout.activity_addfooter, null); mAdapter = new RecycleAdapter3(this); LinearLayoutManager mLinearLayoutManager1 = new LinearLayoutManager(this); mLinearLayoutManager1.setOrientation(OrientationHelper.VERTICAL); recyclerView.setLayoutManager(mLinearLayoutManager1); // recyclerView.setAdapter(mAdapter); } private void addAdapter() { mHeaderAndFooterWrapper = new HeaderAndFooterWrapper(mAdapter); mHeaderAndFooterWrapper.addHeaderView(ll_header); mHeaderAndFooterWrapper.addFootView(ll_footer); recyclerView.setAdapter(mHeaderAndFooterWrapper); }
效果如下图:
4.GridView列表AddHeadAndAddFooter用法核心代码:
private void createAdapter() { ll_header = (LinearLayout) View.inflate(this, R.layout.activity_addheader, null); ll_footer = (LinearLayout) View.inflate(this, R.layout.activity_addfooter, null); mAdapter = new RecycleAdapter4(this); recyclerView.setLayoutManager(new GridLayoutManager(this, 2)); // recyclerView.setAdapter(mAdapter); } private void addAdapter() { mHeaderAndFooterWrapper = new HeaderAndFooterWrapper(mAdapter); mHeaderAndFooterWrapper.addHeaderView(ll_header); mHeaderAndFooterWrapper.addFootView(ll_footer); recyclerView.setAdapter(mHeaderAndFooterWrapper); }
效果如下图:
附:提供了几个常用控件的使用:
1.SwipeReFreshLayout的用法:
onRefresh();
2.ShapeLoading的用法:
ShowLoadingUtil.showProgressDialog2(MainActivity4.this, "正在加载...");
这回够诚意吧~么么哒~下班肥家~吃饭饭~
地址:https://github.com/geeklx/MyApplication/tree/master/p010_recycleviewall
时间: 2024-11-05 18:31:11