当前位置: 首页 > 工具软件 > vlayout > 使用案例 >

vlayout

南门朗
2023-12-01

vlayout全称是VirtualLayout,是一个针对RecyclerView的LayoutManager扩展。是阿里最近开源的一个库,主要提供一整套布局方案和布局间的组件复用的问题。

使用

  1. 导入依赖

compile (‘com.alibaba.android:vlayout:1.0.4@aar’) {
transitive = true
}

2.初始化VirtualLayoutManager

VirtualLayoutManager virtualLayoutManager = new VirtualLayoutManager(this);
mRecylerView.setLayoutManager(virtualLayoutManager);

3.设置缓存view个数

final RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
mRecylerView.setRecycledViewPool(viewPool);
viewPool.setMaxRecycledViews(0, 20);

4.RecylerView创建适配器。初始化DelegateAdapter

adapter = new DelegateAdapter(virtualLayoutManager, false);

  1. 到这步就是处理每一行的代码了,比如。

//第一行
SingleLayoutHelper singleLayoutHelper = new SingleLayoutHelper();
adapterBanner1 = new AdapterBanner(singleLayoutHelper);
//第二行
GridLayoutHelper gridLayoutHelper = new GridLayoutHelper(5);
adapterTowItem = new AdapterTowItem(gridLayoutHelper, this);

6.添加适配器

//添加适配器到
adapter.addAdapter(adapterBanner1);
adapter.addAdapter(adapterTowItem);

    recyclerView.setAdapter(adapter);
    recyclerView.setLayoutManager(virtualLayoutManager);
 类似资料:

相关阅读

相关文章

相关问答