BRVAH BaseMultiItemQuickAdapter多布局实现

首页电商化布局;
各种原因吧,最后决定用列表的形式,
当然除了头部搜索;底部推荐列表位置固定,(滑动效果的限制)
中间部分实现随便变换位置或隐藏显示,后台随时控制的效果,所以想到用BRVAH的多布局实现

当然还遇到了很多问题:

  • 比如嵌套Tablayout切换ViewPager高度自适应
  • 双击Tab回顶部
  • RecycleView横向滑动2个展示平分,3个及以上展示2个半等,有空会再贴出来,当给自己做个记录吧

先上最终效果图:图上标了type对应区域,不要问搜索为何是7,因为后加的哈,不重要

BRVAH BaseMultiItemQuickAdapter多布局实现_第1张图片

好了,开始一顿操作啦啦啦

1、先来首页布局吧,

本来看结构就好,想了一下自己平时浏览的痛苦,还是贴全部吧,




    

    
        

            

                

                    

                    
                

                

            

            
                
            

            

        
    

2、初始化:

presenter.getHomeIndexData();//请求接口
initHomeHeader();//初始化

   /**
     * 初始化首页架构
     */
    private void initHomeHeader() {
        recyclerList.setLayoutManager(new LinearLayoutManager(mActivity));
        multipleHomeAdapter = new MultipleHomeAdapter(mActivity,getMultipleItemData(homeDataList));
        multipleHomeAdapter.setOnLoadMoreListener(null, recyclerList);
        multipleHomeAdapter.disableLoadMoreIfNotFullPage(recyclerList);
//        multipleHomeAdapter.setEmptyView(R.layout.layout_recycler_empty_view);
        recyclerList.setAdapter(multipleHomeAdapter);
    }


   //加载成功
  @Override
    public void getHomeIndexDataSuccess(List data) {
        if (smartRefreshLayout != null) {
            smartRefreshLayout.finishRefresh();
        }
        presenter.dismissLoading();
        rlNoNet.setVisibility(View.GONE);
        appBar.setVisibility(View.VISIBLE);
        this.homeDataList = data;
        multipleHomeAdapter.setNewData(getMultipleItemData(homeDataList));
        initRecommend(); //底部推荐个人项目在此不做赘述
    }

//加载失败
    @Override
    public void getHomeIndexDataFaile() {
        if (smartRefreshLayout != null) {
            smartRefreshLayout.finishRefresh();
        }
        appBar.setVisibility(View.GONE);
        rlNoNet.setVisibility(View.VISIBLE);
        presenter.dismissLoading();
        multipleHomeAdapter.loadMoreComplete();
        multipleHomeAdapter.loadMoreFail();
    }


 //重点转化方法啊,
 /**
     * 添加布局Itemtype
     * @param itemList
     * @return
     */
    private List getMultipleItemData(List itemList) {
        if (null==itemList||itemList.size()<=0){
            return null;
        }
        for (int i=0;i

3、Adapter 处理

public class MultipleHomeAdapter extends BaseMultiItemQuickAdapter {

    private BaseActivity context;

    public MultipleHomeAdapter(BaseActivity context, List data) {
        super(data);
        this.context = context;
        addItemType(HomeIndexBean.TYPE1, R.layout.item_multiple_home_banner);
        addItemType(HomeIndexBean.TYPE2, R.layout.item_multiple_home_operate);
        addItemType(HomeIndexBean.TYPE3, R.layout.item_multiple_home_notice);
        addItemType(HomeIndexBean.TYPE4, R.layout.item_multiple_home_gametype);
        addItemType(HomeIndexBean.TYPE5, R.layout.item_multiple_home_advert);
        //注意,虽然6,7对于我来说在此用不到,但是要写哦,所以我里面设置了空布局
        //至于为什么我没用同一个,因为都用item_multiple_home_empty影响了
        //SmartRefreshLayout的刷新,也不知道为啥,单独引了个布局就好了
        addItemType(HomeIndexBean.TYPE6, R.layout.item_multiple_home_recommend);
        addItemType(HomeIndexBean.TYPE7, R.layout.item_multiple_home_empty);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeIndexBean item) {
        switch (helper.getItemViewType()) {
            case HomeIndexBean.TYPE1: //Banner
                initBannerData(helper,item);
                break;
            case HomeIndexBean.TYPE2: //功能操作
                initOperateData(helper,item);
                break;
            case HomeIndexBean.TYPE3: //公告
                initFlipperData(helper,item);
                break;
            case HomeIndexBean.TYPE4: //游戏分类
                initGameType(helper,item);
                break;
            case HomeIndexBean.TYPE5: //广告
                initAdvertData(helper,item);
                break;
            case HomeIndexBean.TYPE6: //推荐
                break;
            case HomeIndexBean.TYPE7: //搜索
                break;
        }
    }
    }

4、MultiItemEntity

/**
 * Data: 2019/9/27
 * Description:
 *
 * @author: zhanggf
 */
public class HomeIndexBean implements Serializable,MultiItemEntity {
    private int type;
    private HomeIndexListBean data; //自己的数据结构就不贴了

    public static final int TYPE1 = 1;
    public static final int TYPE2 = 2;
    public static final int TYPE3 = 3;
    public static final int TYPE4 = 4;
    public static final int TYPE5 = 5;
    public static final int TYPE6 = 6;
    public static final int TYPE7 = 7; //搜索
    private int itemType;


    @Override
    public int getItemType() {
        return itemType;
    }

    public void setItemType(int itemType) {
        this.itemType = itemType;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public HomeIndexListBean getData() {
        return data;
    }

    public void setData(HomeIndexListBean data) {
        this.data = data;
    }
}

联系QQ:2240949204
参考: BRVAH官方使用指南

你可能感兴趣的:(Android)