在AndroidStudio中引入vlayout
compile('com.alibaba.android:vlayout:1.0.7@aar') {
transitive = true
}
- 1 创建VirtualLayoutManager对象,同时内部会创建一个LayoutHelperFinder对象,用来后续的LayoutHelper查找
VirtualLayoutManager manager = new VirtualLayoutManager(getContext());
mRecyclerView.setLayoutManager(manager);
- 2 设置组件复用回收池
final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
mRecyclerView.setRecycledViewPool(viewPool);
viewPool.setMaxRecycledViews(0, 10);
- 3 设置Adapter列表(同时也是设置LayoutHelper列表)
delegateAdapter = new DelegateAdapter(manager);
-
4 将上述创建的Adapter对象放入到DelegateAdapter.Adapter列表里
adapters = new LinkedList<>();
-
5 适配器添加数据
adapters.add(new BannerAdapter(getContext(), banner, new LinearLayoutHelper(), 1));
* 6 adapters添加到recyclerView中
delegateAdapter.setAdapters(adapters);
mRecyclerView.setAdapter(delegateAdapter);
网友评论