VirtualLayout

1.初始化布局管理器

VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
  • 2.添加数据,设置适配器

  • DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, false);
    List adapters = new LinkedList<>();
    for (int i = 0; i < mlist.size(); i++) {
        //添加标题栏
        addTitle(adapters,mlist.get(i).getCardBankName());
        //添加功能按钮
        addButton(adapters,mlist.get(i).getCardListItemInfo());
    }
    delegateAdapter.setAdapters(adapters);
    recyclerView.setAdapter(delegateAdapter);
/**
 * 添加标题栏
 *
 * @param adapters
 * @param title
 */
private void addTitle(List adapters, String title) {
    LinearLayoutHelper layoutHelper = new LinearLayoutHelper();
    layoutHelper.setPadding(10, 10, 10, 10);
    adapters.add(new AllFuncTitleAdapter(this, layoutHelper, 1, title));
}

 

/**
     * 添加功能按钮
     *
     * @param adapters
     * @param cardListItemInfo
     */
    private void addButton(List adapters,List cardListItemInfo) {
//        GridLayoutHelper layoutHelper = new GridLayoutHelper(4);
        LinearLayoutHelper layoutHelper = new LinearLayoutHelper();
        layoutHelper.setBgColor(Color.WHITE);
//        layoutHelper.setAutoExpand(false);
        layoutHelper.setPadding(10, 10, 10, 10);
        adapters.add(new AllFuncButtonAdapter(this, layoutHelper, cardListItemInfo));
    }

 

private Context mContext;
private LayoutHelper layoutHelper;
private VirtualLayoutManager.LayoutParams mLayoutParams;
private List mList;
new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,100)

 

你可能感兴趣的:(VirtualLayout)