在AndroidStudio中引入vlayout
compile('com.alibaba.android:vlayout:1.0.7@aar') {
transitive = true
}
- 1 創(chuàng)建VirtualLayoutManager對象,同時內(nèi)部會創(chuàng)建一個LayoutHelperFinder對象毅桃,用來后續(xù)的LayoutHelper查找
VirtualLayoutManager manager = new VirtualLayoutManager(getContext());
mRecyclerView.setLayoutManager(manager);
- 2 設(shè)置組件復(fù)用回收池
final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
mRecyclerView.setRecycledViewPool(viewPool);
viewPool.setMaxRecycledViews(0, 10);
- 3 設(shè)置Adapter列表(同時也是設(shè)置LayoutHelper列表)
delegateAdapter = new DelegateAdapter(manager);
-
4 將上述創(chuàng)建的Adapter對象放入到DelegateAdapter.Adapter列表里
adapters = new LinkedList<>();
-
5 適配器添加數(shù)據(jù)
adapters.add(new BannerAdapter(getContext(), banner, new LinearLayoutHelper(), 1));
* 6 adapters添加到recyclerView中
delegateAdapter.setAdapters(adapters);
mRecyclerView.setAdapter(delegateAdapter);