首页 > 代码库 > Android Studio第十三期 - RecycleView所有用法

Android Studio第十三期 - RecycleView所有用法

    综合了一下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

    

    

本文出自 “梁肖技术中心” 博客,请务必保留此出处http://liangxiao.blog.51cto.com/3626612/1855928

Android Studio第十三期 - RecycleView所有用法