{"id":13642562,"url":"https://github.com/alibaba/vlayout","last_synced_at":"2025-09-27T10:31:31.856Z","repository":{"id":47375412,"uuid":"83285138","full_name":"alibaba/vlayout","owner":"alibaba","description":"Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview. ","archived":true,"fork":false,"pushed_at":"2021-07-14T04:40:34.000Z","size":1726,"stargazers_count":10806,"open_issues_count":194,"forks_count":1798,"subscribers_count":336,"default_branch":"master","last_synced_at":"2024-05-21T04:57:14.539Z","etag":null,"topics":["android","layout","layout-manager","layoutmanager","recyclerview-multi-type","tangram"],"latest_commit_sha":null,"homepage":"http://tangram.pingguohe.net/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alibaba.png","metadata":{"files":{"readme":"README-ch.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-27T08:11:47.000Z","updated_at":"2024-05-15T09:20:54.000Z","dependencies_parsed_at":"2022-08-12T13:22:16.426Z","dependency_job_id":null,"html_url":"https://github.com/alibaba/vlayout","commit_stats":null,"previous_names":[],"tags_count":43,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fvlayout","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fvlayout/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fvlayout/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alibaba%2Fvlayout/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alibaba","download_url":"https://codeload.github.com/alibaba/vlayout/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219871973,"owners_count":16554475,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","layout","layout-manager","layoutmanager","recyclerview-multi-type","tangram"],"created_at":"2024-08-02T01:01:33.113Z","updated_at":"2025-09-27T10:31:31.434Z","avatar_url":"https://github.com/alibaba.png","language":"Java","readme":"# 注意，该项目停止维护！！！\n\n# vlayout\n\n[English Document](README.md)\n\n## Tangram 相关开源库\n\n### Android\n\n+ [Tangram-Android](https://github.com/alibaba/Tangram-Android)\n+ [Virtualview-Android](https://github.com/alibaba/Virtualview-Android)\n+ [vlayout](https://github.com/alibaba/vlayout)\n+ [UltraViewPager](https://github.com/alibaba/UltraViewPager)\n\n### iOS\n\n+ [Tangram-iOS](https://github.com/alibaba/Tangram-iOS)\n+ [Virtualview-iOS](https://github.com/alibaba/VirtualView-iOS)\n+ [LazyScrollView](https://github.com/alibaba/lazyscrollview)\n\nVirtualLayout是一个针对RecyclerView的LayoutManager扩展, 主要提供一整套布局方案和布局间的组件复用的问题。\n\n## 设计思路\n\n通过定制化的LayoutManager，接管整个RecyclerView的布局逻辑；LayoutManager管理了一系列LayoutHelper，LayoutHelper负责具体布局逻辑实现的地方；每一个LayoutHelper负责页面某一个范围内的组件布局；不同的LayoutHelper可以做不同的布局逻辑，因此可以在一个RecyclerView页面里提供异构的布局结构，这就能比系统自带的LinearLayoutManager、GridLayoutManager等提供更加丰富的能力。同时支持扩展LayoutHelper来提供更多的布局能力。\n\n## 主要功能\n\n * 默认通用布局实现，解耦所有的View和布局之间的关系: Linear, Grid, 吸顶, 浮动, 固定位置等。\n\t* LinearLayoutHelper: 线性布局\n\t* GridLayoutHelper:  Grid布局， 支持横向的colspan\n\t* FixLayoutHelper: 固定布局，始终在屏幕固定位置显示\n\t* ScrollFixLayoutHelper: 固定布局，但之后当页面滑动到该图片区域才显示, 可以用来做返回顶部或其他书签等\n\t* FloatLayoutHelper: 浮动布局，可以固定显示在屏幕上，但用户可以拖拽其位置\n\t* ColumnLayoutHelper: 栏格布局，都布局在一排，可以配置不同列之间的宽度比值\n\t* SingleLayoutHelper: 通栏布局，只会显示一个组件View\n\t* OnePlusNLayoutHelper: 一拖N布局，可以配置1-5个子元素\n\t* StickyLayoutHelper: stikcy布局， 可以配置吸顶或者吸底\n\t* StaggeredGridLayoutHelper: 瀑布流布局，可配置间隔高度/宽度\n * 上述默认实现里可以大致分为两类：一是非fix类型布局，像线性、Grid、栏格等，它们的特点是布局在整个页面流里，随页面滚动而滚动；另一类就是fix类型的布局，它们的子节点往往不随页面滚动而滚动。\n * 所有除布局外的组件复用，VirtualLayout将用来管理大的模块布局组合，扩展了RecyclerView，使得同一RecyclerView内的组件可以复用，减少View的创建和销毁过程。\n\n\n## 使用\n\n**虽然 vlayout 布局灵活，然而 API 相对原始，手工维护数据及 LayoutHelper 比较麻烦，强烈建议大家使用 [Tangram-Android](https://github.com/alibaba/Tangram-Android) 来间接使用 vlayout，Tangram 具备 vlayout 里所有的功能，且隐藏了细节，通过数据配置即可搭建页面，能避免绝大多数 Issue 里提到的问题，而且重大更新维护主要基于 Tangram，包括局部刷新、响应式接口等。**\n\n版本请参考 [release 说明](https://github.com/alibaba/vlayout/releases)里的最新版本，最新的 aar 都会发布到 jcenter 和 MavenCentral 上，确保配置了这两个仓库源，然后引入aar依赖：\n\n``` gradle \ncompile ('com.alibaba.android:vlayout:1.2.8@aar') {\n\ttransitive = true\n}\n```\n\n或者maven:  \npom.xml\n``` xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.alibaba.android\u003c/groupId\u003e\n  \u003cartifactId\u003evlayout\u003c/artifactId\u003e\n  \u003cversion\u003e1.2.8\u003c/version\u003e\n  \u003ctype\u003eaar\u003c/type\u003e\n\u003c/dependency\u003e\n```\n\n\n初始化```LayoutManager```\n\n``` java\nfinal RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);\nfinal VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);\n\nrecyclerView.setLayoutManager(layoutManager);\n```\n\n设置回收复用池大小，（如果一屏内相同类型的 View 个数比较多，需要设置一个合适的大小，防止来回滚动时重新创建 View）：\n\n``` java\nRecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();\nrecyclerView.setRecycledViewPool(viewPool);\nviewPool.setMaxRecycledViews(0, 10);\n\n```\n\n**注意：上述示例代码里只针对type=0的item设置了复用池的大小，如果你的页面有多种type，需要为每一种类型的分别调整复用池大小参数。**\n\n加载数据时有两种方式:\n\n* 一种是使用 ```DelegateAdapter```, 可以像平常一样写继承自```DelegateAdapter.Adapter```的Adapter, 只比之前的Adapter需要多重载```onCreateLayoutHelper```方法。\n其他的和默认Adapter一样。\n\n``` java\nDelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager, hasConsistItemType);\nrecycler.setAdapter(delegateAdapter);\n\n// 之后可以通过 setAdapters 或 addAdapter方法添加DelegateAdapter.Adapter\n\ndelegateAdapter.setAdapters(adapters);\n\n// or\nCustomAdapter adapter = new CustomAdapter(data, new GridLayoutHelper());\ndelegateAdapter.addAdapter(adapter);\n\n// 如果数据有变化，调用自定义 adapter 的 notifyDataSetChanged()\nadapter.notifyDataSetChanged();\n```\n**注意：当hasConsistItemType=true的时候，不论是不是属于同一个子adapter，相同类型的item都能复用。表示它们共享一个类型。\n当hasConsistItemType=false的时候，不同子adapter之间的类型不共享**\n\n* 另一种是当业务有自定义的复杂需求的时候, 可以继承自```VirtualLayoutAdapter```, 实现自己的Adapter\n\n``` java\npublic class MyAdapter extends VirtualLayoutAdapter {\n   ......\n}\n\nMyAdapter myAdapter = new MyAdapter(layoutManager);\n\n//构造 layoutHelper 列表\nList\u003cLayoutHelper\u003e helpers = new LinkedList\u003c\u003e();\nGridLayoutHelper gridLayoutHelper = new GridLayoutHelper(4);\ngridLayoutHelper.setItemCount(25);\nhelpers.add(gridLayoutHelper);\n\nGridLayoutHelper gridLayoutHelper2 = new GridLayoutHelper(2);\ngridLayoutHelper2.setItemCount(25);\nhelpers.add(gridLayoutHelper2);\n\n//将 layoutHelper 列表传递给 adapter\nmyAdapter.setLayoutHelpers(helpers);\n\n//将 adapter 设置给 recyclerView\nrecycler.setAdapter(myAdapter);\n\n```\n\n在这种情况下，需要使用者注意在当```LayoutHelpers```的结构或者数据数量等会影响到布局的元素变化时，需要主动调用```setLayoutHelpers```去更新布局模式。\n\n另外如果你的应用有混淆配置，请为vlayout添加一下防混淆配置：\n\n```\n-keepattributes InnerClasses\n-keep class com.alibaba.android.vlayout.ExposeLinearLayoutManagerEx { *; }\n-keep class android.support.v7.widget.RecyclerView$LayoutParams { *; }\n-keep class android.support.v7.widget.RecyclerView$ViewHolder { *; }\n-keep class android.support.v7.widget.ChildHelper { *; }\n-keep class android.support.v7.widget.ChildHelper$Bucket { *; }\n-keep class android.support.v7.widget.RecyclerView$LayoutManager { *; }\n```\n\n# Demo\n\n![](http://img3.tbcdn.cn/L1/461/1/1b9bfb42009047f75cee08ae741505de2c74ac0a)\n\n[Demo工程](https://github.com/alibaba/vlayout/tree/master/examples)\n\n# FAQ\n\n使用之前或者碰到问题的时候，建议先看看其他[FAQ](docs/VLayoutFAQ.md)。\n\n# 布局属性\n\n每一种layoutHelper都有自己的布局属性来控制布局样式，详情请参考[文档](docs/ATTRIBUTES-ch.md)。\n\n# 贡献代码\n\n在提 Issue 或者 PR 之前，建议先阅读[Contributing Guide](CONTRIBUTING.md)。按照规范提建议。\n\n# 开源许可证\n\nvlayout遵循MIT开源许可证协议。\n","funding_links":[],"categories":["Android 应用","布局","Projects List"],"sub_categories":["网络服务_其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba%2Fvlayout","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falibaba%2Fvlayout","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falibaba%2Fvlayout/lists"}