1.初始化布局管理器
VirtualLayoutManager layoutManager = new VirtualLayoutManager(this); recyclerView.setLayoutManager(layoutManager);
-
2.添加数据,设置适配器
-
DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, false); List<DelegateAdapter.Adapter> 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<DelegateAdapter.Adapter> 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<DelegateAdapter.Adapter> adapters,List<CardListItemInfo> 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<CardListItemInfo> mList;new VirtualLayoutManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,100)